Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <cstring>
- using namespace std;
- ifstream f("catchy.in");
- ofstream g("catchy.out");
- char s[1501],*p,separator[]=" ,:;)(.?!><}{",cuv[100000][25];
- struct CUV
- {
- char c[25];
- int F;
- };
- CUV C[100000];
- char cuvc[1501][25];
- int FRECV;
- bool cautbin(char s[25],int st,int dr)
- {
- if(strcmp(s,C[(st+dr)/2].c)==0)
- {
- FRECV=C[(st+dr)/2].F;
- return true;
- }
- else
- if(st<dr)
- if(strcmp(s,C[(st+dr)/2].c)==-1)
- cautbin(s,st,(st+dr)/2 -1);
- else
- cautbin(s,(st+dr)/2+1,dr);
- else
- return false;
- }
- int main()
- {
- int K,nr=0;
- f>>K;
- for(int i=1;i<=K;++i) /// Separam cuvintele si le memoram in vectorul cuv
- {
- f.get();
- f.get(s,1501);
- p=s;
- p=strtok(p,separator);
- while(p)
- strcpy(cuv[++nr],p),p=strtok(NULL,separator);
- }
- bool gata;
- for(int i=1;i<nr;++i) /// Sortam vectorul lexicografic
- {
- gata=true;
- for(int j=i+1;j<=nr;++j)
- if(strcmp(cuv[i],cuv[j])==1)
- strcpy(s,cuv[i]),strcpy(cuv[i],cuv[j]),strcpy(cuv[j],s),gata=false;
- if(gata)
- break;
- }
- /*for(int i=1;i<=nr;++i)
- g<<cuv[i]<<'\n';
- g<<endl;*/
- int NR;
- strcpy(C[1].c,cuv[1]);NR=1;C[1].F=1;
- for(int i=2;i<=nr;++i)
- if(strcmp(cuv[i],C[NR].c)==0)
- ++C[NR].F;
- else
- strcpy(C[++NR].c,cuv[i]),C[NR].F=1;
- /*g<<"=========================="<<endl;
- for(int i=1;i<=NR;++i)
- g<<C[i].c<<' '<<C[i].F<<endl;
- g<<endl;*/
- int N,NRB=0,NREX=0;
- f>>N;
- for(int i=1;i<=N;++i)
- {
- f.get();
- f.get(s,1501);
- p=s;
- p=strtok(p,separator);
- int nrc=0,MIN=1000000000;
- while(p)
- {
- strcpy(cuvc[++nrc],p),p=strtok(NULL,separator);
- /// Aici caut daca banerul poate fi realizat si de cate ori
- if(cautbin(cuvc[nrc],1,NR))
- {
- if(FRECV<MIN)
- MIN=FRECV;
- }
- else
- {
- MIN=0;
- break;
- }
- }
- if(MIN>NREX)
- NRB=i,NREX=MIN;
- }
- g<<NRB<<'\n'<<NREX<<'\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement