缘由一提标准的大一oj提木-编程语言-CSDN问答
void 统计以空格隔开的字符串数量()
{//缘由https://ask.csdn.net/questions/7580109?spm=1005.2025.3001.5141
int n = 0, x = 0, g = 0, k = 1;
string s = "";
cin >> n;
getchar();
while (n--)
{
getline(cin, s);
while (s[x] != '\0'&&x < s.length())//s.size()
(s[x] == ' ' ? k = 1 : (k ? ++g, k = 0 : 0)), ++x;
cout << g << endl;
k = 1;
x = g = 0;
}
}
void 统计以符号隔开的字符串数量()
{//缘由https://ask.csdn.net/questions/7580069?spm=1005.2025.3001.5141
int n = 0, x = 0, g = 0, k = 1;
string s = "";
cin >> n;
getchar();
while (n--)
{
getline(cin, s);
while (s[x] != '\0'&&x < s.length())//s.size()
(s[x] == ' ' || s[x] == ',' || s[x] == '.' || s[x] == ';' ?
k = 1 : (k ? ++g, k = 0 : 0)), ++x;
cout << g << endl;
k = 1;
x = g = 0;
}
}
统计不受任何空格影响。