Codeforces 53A Autocomplete

Autocomplete
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

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
next
2
nextpermutation
nextelement
Output
nextelement
Input
find
4
find
findfirstof
findit
fand
Output
find
Input
find
4
fondfind
fondfirstof
fondit
fand
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;
}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值