[String watermark] codechef November cook-off -- subanagrams

Source: Internet
Author: User

The first official participation in the codechef competition. It is a CF-like website in India, but I saw its comments earlier than CF (CF seems to have been established in 10 years)

This website seems to have this XX cook off every month, and the question is not as easy as CF (this is from hard to easy... I don't know how it was)

Okay, let's start with the question. At first, I habitually read question a and thought about it for 10 minutes (I thought it was the CF model). Let's refresh it, the last question was found to be the best in the audience! Please refer to the following link for more information! If you do not need any advanced algorithms, you just need to use them to obtain the number of occurrences of 26 letters in each line. Then, you can scan n rows to find n rows of Public letters (note that they can be repeated, for example, "HPP", 1wa at first ).

#include <map>#include <set>#include <list>#include <queue>#include <deque>#include <stack>#include <string>#include <time.h>#include <cstdio>#include <math.h>#include <iomanip>#include <cstdlib>#include <limits.h>#include <string.h>#include <iostream>#include <fstream>#include <algorithm>using namespace std; #define LL long long#define MIN INT_MIN#define MAX INT_MAX#define PI acos(-1.0)#define FRE freopen ("input.txt","r",stdin)#define FF  freopen ("output.txt","w",stdout)#define eps 1e-8#define N 50005char str[110];int cnt[110][30];bool vis[30];int ans[30];void gao(int k,int id){    int i;    for (i = 0 ; i < k ; i++)printf("%c",id+'a');}int  main(){    int n;    while(scanf("%d",&n) != -1 ){        int i,j;        memset(cnt,0,sizeof(cnt));        for (i = 0 ; i < n ;i++ ){            scanf("%s",str);            for (j = 0; j < strlen(str); j++) {                int id = str[j] - 'a';                    vis[id] = 1;                    cnt[i][id]++;            }        }        int k = 0;        bool ok = 0;        for (i = 0 ; i < 26; i++){            int minm = MAX;            for (j = 0; j < n; j++) {                if (cnt[j][i] == 0) {                    break;                }                else minm = min(cnt[j][i],minm);            }            if (j >= n) {                gao(minm,i);                ok = 1;            }        }        if (!ok) printf("no such string");        puts("");    }    return 0;} 

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.