---
# System prepended metadata

title: UVA 10252 Common Permutation

---

# UVA 10252 Common Permutation 
##  題目連結 [UVA 10252](https://vjudge.net/problem/UVA-10252)
### 題目內容
Given two strings of lowercase letters, a and b, print the longest string x of lowercase letters such that there is a permutation of x that is a subsequence of a and there is a permutation of x that is a subsequence of b.
### 輸入限制
Input file contains several lines of input. Consecutive two lines make a set of input. That means in the input file line 1 and 2 is a set of input, line 3 and 4 is a set of input and so on. The first line of a pair contains a and the second contains b. Each string is on a separate line and consists of at most 1000 lowercase letters
### 輸出限制
For each set of input, output a line containing x. If several x satisfy the criteria above, choose the first one in alphabetical order.

### 解題思路
計算出兩字串每個字母的頻率，要輸出比較小的那一方的相同字母數，要注意的是當有其中一字串的內容為空白，就必須輸出空白。
### 程式碼
```cpp=
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a,b;
    int cota[26],cotb[26];
    while(getline(cin,a)){
        getline(cin,b);
        if(a==" " || b==" "){
            cout<<"\n";
        }
        memset(cota,0,sizeof cota);
        memset(cotb,0,sizeof cotb);
        for(int i=0;i<a.length();i++){
            cota[a[i]-'a']++;
        }
        for(int i=0;i<b.length();i++){
            cotb[b[i]-'a']++;
        }
        for(int i=0;i<26;i++){
            for(int j=min(cota[i],cotb[i]);j>0;j--){
                cout<<(char)('a'+i);
            }
        }
        cout<<"\n";
    }
}

```
## 測資
### Sample input
pretty
women
walking
down
the
street
### Sample output
e
nw
et
##  中文題目連結 [zerojudge e507](https://zerojudge.tw/ShowProblem?problemid=e507)