uva124

来源:互联网 发布:sketchup看图软件 编辑:程序博客网 时间:2024/06/04 20:00
#include <iostream>#include <stdio.h>#include <algorithm>#include <string.h>using namespace std;char v[21];char c[500];bool map_[26][26];int main(){    //freopen("debug\\in.txt","r",stdin);    //freopen("debug\\out.txt","w",stdout);    int t=0;    while(gets(v))//gets()读取带空格的字符串    {        if(t) printf("\n");        memset(map_,0,sizeof(map_));        remove(v,&v[sizeof(v)],' ');        int len=strlen(v);        sort(v,v+len);//为了方便后面的全排列        gets(c);        remove(c,&c[sizeof(c)],' ');        int len1=strlen(c);        for(int i=0; i<len1; i+=2)            map_[c[i]-'a'][c[i+1]-'a']=1;        do        {            bool flag=true;            for(int i=0; i<len; i++)                for(int j=i+1; j<len; j++)                    if(map_[v[j]-'a'][v[i]-'a'])                        flag=false;            if(flag) printf("%s\n",v);        }        while(next_permutation(v,&v[len]));//这个next_permutation()可以重新排列定义的范围内的字符串        t++;    }    return 0;}
#include <iostream>#include <algorithm>#include <string.h>using namespace std;int main(){    string s="1122234225";    remove(s.begin(),s.end(),'2');    cout<<s;    return 0;}//输出:1134534225,把后面不是2的向前移动,后面的5个和原来保持一样,没有变化,//如果想把后面的也删除掉,就用erase();
#include <iostream>#include <algorithm>#include <string.h>using namespace std;int main(){    string s="1122234225";    s.erase(remove(s.begin(),s.end(),'2'),s.end());    cout<<s;    return 0;}输出:11345