牛客OI周赛14-普及组-----1 Sring
链接:https://ac.nowcoder.com/acm/contest/4479/A
来源:牛客网
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
牛牛给定一个长度为|S|的字符串S,S中仅包含大小写字母和数字,请你帮他计算出S中有多少种不同的字符
输入描述:
一行,一个字符串,S
输出描述:
一行,一个数字,不同的字符种数
示例1
输入
复制
aaaba21AbB
输出
复制
6
备注:
对于60%60%的数据,1\leq |S| \leq 10001≤∣S∣≤1000
对于100%100%的数据,1\leq |S| \leq 10000001≤∣S∣≤1000000
按照题意即 统计字符种类数
#include <iostream>
#include <string>
using std::string;
using namespace std;
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
string s;
while (getline(cin,s))
{
char c(0);
int n(0);
for (int i = 1 ; i <= 127 ;++i ) //遍历所有种字符
{
c = i;
if (s.find( c ) != string::npos) //查找
++n;
}
cout << n << '\n';
}
return 0;
}