Advertisement
a53

C_a_t_c_h_y

a53
Aug 14th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. #include <fstream>
  2. #include <cstring>
  3. using namespace std;
  4. ifstream f("catchy.in");
  5. ofstream g("catchy.out");
  6. char s[1501],*p,separator[]=" ,:;)(.?!><}{",cuv[100000][25];
  7. struct CUV
  8. {
  9. char c[25];
  10. int F;
  11. };
  12. CUV C[100000];
  13. char cuvc[1501][25];
  14. int FRECV;
  15.  
  16. bool cautbin(char s[25],int st,int dr)
  17. {
  18. if(strcmp(s,C[(st+dr)/2].c)==0)
  19. {
  20. FRECV=C[(st+dr)/2].F;
  21. return true;
  22. }
  23. else
  24. if(st<dr)
  25. if(strcmp(s,C[(st+dr)/2].c)==-1)
  26. cautbin(s,st,(st+dr)/2 -1);
  27. else
  28. cautbin(s,(st+dr)/2+1,dr);
  29. else
  30. return false;
  31. }
  32.  
  33. int main()
  34. {
  35. int K,nr=0;
  36. f>>K;
  37. for(int i=1;i<=K;++i) /// Separam cuvintele si le memoram in vectorul cuv
  38. {
  39. f.get();
  40. f.get(s,1501);
  41. p=s;
  42. p=strtok(p,separator);
  43. while(p)
  44. strcpy(cuv[++nr],p),p=strtok(NULL,separator);
  45. }
  46. bool gata;
  47. for(int i=1;i<nr;++i) /// Sortam vectorul lexicografic
  48. {
  49. gata=true;
  50. for(int j=i+1;j<=nr;++j)
  51. if(strcmp(cuv[i],cuv[j])==1)
  52. strcpy(s,cuv[i]),strcpy(cuv[i],cuv[j]),strcpy(cuv[j],s),gata=false;
  53. if(gata)
  54. break;
  55. }
  56. /*for(int i=1;i<=nr;++i)
  57. g<<cuv[i]<<'\n';
  58. g<<endl;*/
  59. int NR;
  60. strcpy(C[1].c,cuv[1]);NR=1;C[1].F=1;
  61. for(int i=2;i<=nr;++i)
  62. if(strcmp(cuv[i],C[NR].c)==0)
  63. ++C[NR].F;
  64. else
  65. strcpy(C[++NR].c,cuv[i]),C[NR].F=1;
  66. /*g<<"=========================="<<endl;
  67. for(int i=1;i<=NR;++i)
  68. g<<C[i].c<<' '<<C[i].F<<endl;
  69. g<<endl;*/
  70. int N,NRB=0,NREX=0;
  71. f>>N;
  72. for(int i=1;i<=N;++i)
  73. {
  74. f.get();
  75. f.get(s,1501);
  76. p=s;
  77. p=strtok(p,separator);
  78. int nrc=0,MIN=1000000000;
  79. while(p)
  80. {
  81. strcpy(cuvc[++nrc],p),p=strtok(NULL,separator);
  82. /// Aici caut daca banerul poate fi realizat si de cate ori
  83. if(cautbin(cuvc[nrc],1,NR))
  84. {
  85. if(FRECV<MIN)
  86. MIN=FRECV;
  87. }
  88. else
  89. {
  90. MIN=0;
  91. break;
  92. }
  93. }
  94. if(MIN>NREX)
  95. NRB=i,NREX=MIN;
  96. }
  97. g<<NRB<<'\n'<<NREX<<'\n';
  98. return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement