소ê°� ¶
2005/02/19 Accepted 0:00.002 64
ASCII 코드를 �용하여 소문�를 0~26� 숫�로 �코딩시켰다. 그 �코딩 숫�를 �용한 배열� 만들어서 그 배열�리 비�를 해서 공통� 변경 문�열� 쉽게 만들수 있었다.
ASCII 코드를 �용하여 소문�를 0~26� 숫�로 �코딩시켰다. 그 �코딩 숫�를 �용한 배열� 만들어서 그 배열�리 비�를 해서 공통� 변경 문�열� 쉽게 만들수 있었다.
코드 ¶
~cpp
// no10252 - Common Permutation
#include <iostream>
#include <cstring>
using namespace std;
const int MAX = 1000;
int main()
{
char str[MAX+1];
int first[26], second[26];
int len, min, count;
int i, j;
while (cin.getline(str, MAX+1, '\n'))
{
/* ìž…ë ¥ */
for (i=0; i<26; i++)
first[i] = second[i] = 0;
len = strlen(str);
for (i=0; i<len; i++)
first[str[i]-97]++;
cin.getline(str, MAX+1, '\n');
len = strlen(str);
for (i=0; i<len; i++)
second[str[i]-97]++;
/* 변경 문�열 찾기 */
count = 0;
for (i=0; i<26; i++)
{
if (first[i] == 0 || second[i] == 0)
continue;
if (first[i] < second[i])
min = first[i];
else
min = second[i];
for (j=0; j<min; j++)
str[count++] = i + 97;
}
str[count] = '\0';
cout << str << endl;
}
return 0;
}










