UVa 10252 Common permutation (water ver.)

Source: Internet
Author: User
Tags lowercase strlen time limit

10252-common permutation

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=1193

Given two strings of lowercase letters, a and B, print the longest string x of lowercase letters such that's there is a perm Utation of X that's a subsequence of a and there is a permutation OFX this is a subsequence of B.

Input

Input file contains several lines of input. Consecutive two lines make a set of input. That means in the input file line1 and 2 are a set of input, line 3 And4 are a set of input and so on. The A pair Containsa and the second contains B. Each of the separate line and consists of an at most1000 lowercase letters.

Output

For each set of input, output a line containingx. If several x satisfy the criteria above, choose the "one in alphabetical" order.

Sample Input:

Pretty
Women
Walking
Down
The
Street

Sample Output:

E

nw

Et

Water.

Complete code:

/*0.019s*/
    
#include <bits/stdc++.h>  
using namespace std;  
    
Char a[1005], b[1005], ans[1005];  
BOOL vis[1005];  
    
void Solve (char* A, char* b)  
{  
    int lena = strlen (a), LenB = strlen (b), I, j, c = 0;  
    memset (Vis, 0, sizeof (VIS));  
    for (i = 0; i < Lena. ++i) for  
        (j = 0; j < LenB; ++j)  
        {  
            if (!vis[j] && a[i] = = B[j])  
            {
  ans[c++] = A[i];  
                VIS[J] = true;  
                break;  
            }  
        }  
    Ans[c] = 0;  
    Sort (ans, ans + c);  
    Puts (ans);  
    
int main ()  
{while  
    (gets (a))  
    {  
        gets (b);  
        if (strlen (a) < strlen (b)) solve (A, b);  
        else Solve (b, a);  
    }  
    return 0;  
}

This article URL address: http://www.bianceng.cn/Programming/sjjg/201410/45441.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.