uva124

11 篇文章 0 订阅
#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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值