本文主要是介绍字符串 UVa 10252 Common Permutation (公共排列),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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;
}
这篇关于字符串 UVa 10252 Common Permutation (公共排列)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!