标签:str 20px time 集合 标点符号 code 数据 class mono
you are my friend #
4set集合使用方法及特点:1。set中的元素从小到大排列且和集合一样没有反复元素。2,set<string>::iterator s.begin() s.end()#include<iostream> # include<cstring> #include<cstdio> # include<sstream> # include<string> #include<set> using namespace std; string wen,str; set<string> dict; int main() { while(getline(cin,wen)&&wen!="#") { stringstream ch(wen); //在文本串中找单个单词 while(ch >>str) dict.insert(str); printf("%d\n",dict.size()); dict.clear(); } return 0; }
#include<iostream> # include<cstdio> # include<string> # include<map> # include<cstring> # include<sstream> using namespace std; map<string ,int> m; string str,ch; /* int main() { while(getline(cin,str)&&str!="#") { int len=str.size(); int i=0; m.clear(); while(i<len) { ch=""; while(i<len&&‘a‘<=str[i]&&str[i]<=‘z‘) ch+=str[i++]; if(ch!="") { m[ch]=1; } i++; } printf("%d\n",m.size()); } return 0; }*/ int main() { while(getline(cin,str)&&str!="#") { stringstream ss(str); m.clear(); while(ss>>ch) { m[ch]=1; } printf("%d\n",m.size()); } return 0; }
标签:str 20px time 集合 标点符号 code 数据 class mono
原文地址:http://www.cnblogs.com/brucemengbm/p/6912776.html