【问题描述】
从下标 1 处开始输入字符串的一种 C++ 语法:scanf("%s",str+1);
由于下标从 1 开始,故求字符串的长度的 C++ 语法为:strlen(str+1);
其中,上文中的 str 为字符数组。
【算法代码】
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
char str[N];
int main() {
scanf("%s",str+1); //从s的首地址+1开始输入
int len=strlen(str+1);
cout<<len<<endl;
for(int i=1; i<=len; i++) cout<<str[i]<<" ";
return 0;
}
/*
in:
abcde
out:
5
a b c d e
*/