比较数字的出现次数是否一样可以通过vector先排序,然后直接比较vector的大小,vector支持比较大小
逗号表达式的值是最后一项的值
while(cin>>n>>d,n>>1)
处理读入
都用字符串来读入
sstream
:类似于sscanf,对象用于输入一行字符串,以 空格 为分隔符把该行分隔开来
#include <iostream> #include <sstream> while(n--){ string line; getline(cin,line);//读入一整行 stringstream ssin(line); if(line[0]<='9'){ int v; ssin>>v; if(v<13)cout<<names[v]<<endl; else{ cout<<names[12+v/13]; if(v%13==0)cout<<endl; else cout<<' '<<names[v%13]<<endl; } } else{ int res=0; string word; while(ssin>>word)res+=get(word); cout<<res<<endl; } }sstream还可实现类型的转换
stringstream buff4; buff4.str("23333"); int i; buff4>>i; cout<<i<<endl;
小技巧:单词中间加引号,可以用替换ctrl+H