CF443A Anton and Letters(去重set函数)

简介: CF443A Anton and Letters(去重set函数)

A. Anton and Letters


time limit per test


2 seconds


memory limit per test


256 megabytes


input


standard input


output


standard output


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.


Input


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.


Output


Print a single number — the number of distinct letters in Anton's set.


Examples


input

Copy

{a, b, c}


output

Copy

3


input

Copy

{b, a, b, a}


output

Copy

2


input

Copy

{}


output

Copy

0


题意分析,我们可以看到这里是应该字符串还有空格,所以我们不能用cin>>n输入,如果要用那么就getline(cin,n)来,但是我们这里可以用set函数解,具体实现看代码。


#include<bits/stdc++.h>
using namespace std;
set<char>ans;//char类型的集合
char n;
int main()
{
  while(cin>>n&&n!='}')//不断输入
  {
    if(n>='a'&&n<='z')//是小写字母
    ans.insert(n);//塞入集合
  }
  cout<<ans.size()<<endl;//输出集合的大小
}


正常的做法

 

#include<bits/stdc++.h>
using namespace std;
int main()
{
  char b;
  cin>>b;int ans[27]={0},sum=0;
  while(b!='}')
  {
    cin>>b;
    if(b>='a'&&b<='z')
    {
      ans[b-'a']++;
    }
  }
  for(int i=0;i<=26;i++)
  {
    if(ans[i])sum++;
  }
  cout<<sum;
}
相关文章
|
20天前
|
SQL HIVE
数仓学习-----named_struct和collect_set函数
数仓学习-----named_struct和collect_set函数
|
18天前
|
数据采集 Python
10个Python set 常用操作函数!,bilibili面试题
10个Python set 常用操作函数!,bilibili面试题
10个Python set 常用操作函数!,bilibili面试题
|
8月前
|
SQL 分布式计算 大数据
`collect_set`函数用于将一组数据收集到一个集合中
`collect_set`函数用于将一组数据收集到一个集合中
92 1
|
8月前
|
分布式计算 MaxCompute
MaxCompute中,collect_set函数是一个聚合函数
MaxCompute中,collect_set函数是一个聚合函数
95 1
|
10月前
|
前端开发 JavaScript API
ES6-ES11-第一部分-let、const、解构赋值、模板字符串、简化对象写法、箭头函数、函数参数默认值、rest 参数、扩展运算符、Symbol、迭代器、生成器、Promise、Set、Map(五)
ES6-ES11-第一部分-let、const、解构赋值、模板字符串、简化对象写法、箭头函数、函数参数默认值、rest 参数、扩展运算符、Symbol、迭代器、生成器、Promise、Set、Map(五)
|
20天前
|
JSON 前端开发 JavaScript
【面试题】面试官:请你实现一个深拷贝,那如果是正则/set/函数怎么拷贝?
【面试题】面试官:请你实现一个深拷贝,那如果是正则/set/函数怎么拷贝?
|
8月前
|
存储 索引 Python
python-tuple(元组)-set(集合)-list(列表)-dictionary(字典)和Python数据类型转换函数
python-tuple(元组)-set(集合)-list(列表)-dictionary(字典)和Python数据类型转换函数
|
关系型数据库 MySQL 数据库
MySQL中find_in_set函数的使用
1.语法 FIND_IN_SET(str,strlist) (1)str 要查询的字符串 (2)strlist 字段名; 参数以”,”分隔 如 (1,2,6,8) 查询字段(strlist)中包含(str)的结果,返回结果为null或记录 假如字符串str在由N个子链组成的字符串列表strlist 中,则返回值的范围在 1 到 N 之间。 一个字符串列表就是一个由一些被 ‘,’ 符号分开的子链组成的字符串。如果第一个参数是一个常数字符串,而第二个是type SET列,则FIND_IN_SET() 函数被优化,使用比特计算。 如果str不在strlist 或strlist 为空字符串,则返回
MySQL中find_in_set函数的使用
|
10月前
|
前端开发 API 网络架构
ES6-ES11-第一部分-let、const、解构赋值、模板字符串、简化对象写法、箭头函数、函数参数默认值、rest 参数、扩展运算符、Symbol、迭代器、生成器、Promise、Set、Map(六)
ES6-ES11-第一部分-let、const、解构赋值、模板字符串、简化对象写法、箭头函数、函数参数默认值、rest 参数、扩展运算符、Symbol、迭代器、生成器、Promise、Set、Map(六)