Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Print a single number — the number of distinct letters in Anton's set.
{a, b, c}
3
{b, a, b, a}
2
{}
0#include<cstring> #include<cstdio> #include<iostream> using namespace std; int num[25]; char s[1100]; int main(){ int n,len,sum,i; while(gets(s)){ sum=0; memset(num,0,sizeof(num)); len=strlen(s); for(i=0;i<len;i++){ if(s[i]>='a'&&s[i]<='z'){ num[s[i]-'a']=1; } } for(i=0;i<=25;i++){ if(num[i]==1){ sum++; } } cout<<sum<<endl; } return 0; }
本博客介绍了一种方法,用于计算给定集合中所有不重复的小写字母的数量,通过读取输入字符串并使用数组来跟踪每个字母的出现情况。
502

被折叠的 条评论
为什么被折叠?



