Codeforces 53A Autocomplete

来源:互联网 发布:零基础学php要多久 编辑:程序博客网 时间:2024/05/21 14:56

Autocomplete
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 53A

Description

Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing 

the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the 

autocomplete function in the address line at this very moment. A list consisting of n last visited by the user pages and the 

inputted part s are known. Your task is to complete s to make it an address of one of the pages from the list. You have to 

find the lexicographically smallest address having a prefixs.

Input

The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 100) which is the
number of visited pages. Then follow n lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only.

Output

If s is not the beginning of any of n addresses of the visited pages, print s. Otherwise, print the lexicographically minimal
address of one of the visited pages starting from s.

The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by
the '<' operator in the modern programming languages.

Sample Input

Input
next2nextpermutationnextelement
Output
nextelement
Input
find4findfindfirstoffinditfand
Output
find
Input
find4fondfindfondfirstoffonditfand
Output
find


#include<stdio.h>#include<string.h>char s[1004][1004];int r[1004],c[1004];int main(){    int n,m,i,j;    __int64 ans,tem;    while(scanf("%d%d",&n,&m)!=EOF)    {        memset(r,0,sizeof(r));        memset(c,0,sizeof(c));        for(i=0; i<n; i++)        {            scanf("%s",s[i]);            for(j=0; j<m; j++)                if(s[i][j]=='*')                {                    r[i]++;                    c[j]++;                }        }        ans=0;        for(j=0; j<m; j++)        {            tem=0;            for(i=0; i<n; i++)                if(s[i][j]=='*')                    tem+=r[i]-1;            ans+=tem*(c[j]-1);        }        printf("%I64d\n",ans);    }    return 0;}


0 0
原创粉丝点击