题目描述
凯凯刚写了一篇美妙的作文,请问这篇作文的标题中有多少个字符? 注意:标题中可能包含大、小写英文字母、数字字符、空格和换行符。统计标题字 符数时,空格和换行符不计算在内。
输入格式
输入文件只有一行,一个字符串 ss。
输出格式
输出文件只有一行,包含一个整数,即作文标题的字符数(不含空格和换行符)。
输入输出样例
输入 #1
234
输出 #1
3
输入 #2
Ca 45
输出 #2
4
说明/提示
【输入输出样例 1 说明】
标题中共有 3 个字符,这 3 个字符都是数字字符。
【输入输出样例 2 说明】 标题中共有55 个字符,包括 11 个大写英文字母, 11 个小写英文字母和 22 个数字字符, 还有 11 个空格。由于空格不计入结果中,故标题的有效字符数为 44 个。
【数据规模与约定】
规定 |s|∣s∣ 表示字符串 ss 的长度(即字符串中的字符和空格数)。
对于 40\%40% 的数据,1 ≤ |s| ≤ 51≤∣s∣≤5,保证输入为数字字符及行末换行符。
对于 80\%80% 的数据,1 ≤ |s| ≤ 51≤∣s∣≤5,输入只可能包含大、小写英文字母、数字字符及行末换行符。
对于 100\%100% 的数据,1 ≤ |s| ≤ 51≤∣s∣≤5,输入可能包含大、小写英文字母、数字字符、空格和行末换行符。
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <climits>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <list>
#include <stack>
#include <string.h>
using namespace std;
int main(void)
{
string str;
getline(cin, str);
unsigned long long count = 0;
for(int i = 0; i < str.size(); i++)
{
if((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z') || (str[i] >= '0' && str[i] <= '9'))
count++;
}
cout << count << endl;
return 0;
}