字符串 UVa 10252 Common Permutation (公共排列)

来源:互联网 发布:中京域名交易中心 编辑:程序博客网 时间:2024/04/27 16:29

UVa 10252 Common Permutation 

水题一枚, 找出两串中相同的每一个字符, 按字典序排列输出即可
#include <iostream>using namespace std;#include <algorithm>#include <stdio.h>#include <string.h>char a[1005];char b[1005];char c[1005];int main(){    while (gets(a) != NULL && gets(b) != NULL)    {memset(c, 0, sizeof(c));int t = 0;for (int i = 0; i < strlen(a); i ++){    for (int j = 0; j < strlen(b); j ++)    {if (a[i] == b[j]){    c[t ++] = a[i];    b[j] = '*';    break;}    }}c[t] = '\0';sort(c, c + t);printf("%s\n", c);    }    return 0;}


原创粉丝点击