uva10185set的自动排序和自动去重以及遍历和string的的辅助问题

来源:互联网 发布:网络钟点工招聘 编辑:程序博客网 时间:2024/04/27 10:11

set的排序和去重以及遍历看下面程序,string是一个类所以不能把一个char型字符赋值给string,但是char型数组可以,

另外在不同的编译器上对于string以什么结尾的说法不一,最好不要用string的有效字符的后面一位来做一些事情。

#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<cctype>#include<cmath>#include<set>using namespace std;int main(){    set<string> s;    string ss;    char x[205];    char c;    int len=0;    while((c=getchar())!=EOF)    {        if(isalpha(c))        {            c=tolower(c);            x[len++]=c;        }        else        {            x[len]='\0';            ss=x;            if(len)            s.insert(ss);            len=0;        }    }   // cout<<s.size()<<endl;    set<string>::iterator it;    for(it=s.begin();it!=s.end();it++)        cout<<*it<<endl;    return 0;}


0 0
原创粉丝点击