1885 - 【C语言训练】数字母

输入一个字符串,数出其中的字母的个数.

题目输入

一个字符串,不包含空格(长度小于100)

题目输出

字符串中的字母的个数

输入/输出样例

题目输入

124lfdk54AIEJ92854&%$GJ

题目输出

10

C++解答

#include<iostream>
#include<string>
#include<cctype>
using namespace std;
int main()
{
	string s;
	getline(cin,s);
	int len=s.size(),ans=0;
	for (int i=0; i<len; i++)
		if (isalpha(s[i])) ans++;
	cout<<ans<<endl;
	return 0;
}
时间限制 1 秒
内存限制 128 MB
讨论 统计
上一题 下一题