#include <iostream>
using namespace std;
int Count(char *str)
{
char *p = str;
while(*p != '\0')
p++;
int count = p - str;
return count;
}
int main() {
char str[100] = { 0 };
cin.getline(str, sizeof(str));
// write your code here......
int count = Count(str);
printf("%d",count);
return 0;
}
主要是利用两指针的差为其中间的元素差,进行计算。

京公网安备 11010502036488号