Advertisement
a53

careu

a53
Jan 29th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. #include <fstream>
  2. #include <cstring>
  3. #define Nmax 51
  4. using namespace std;
  5. ifstream f("careu.in");
  6. ofstream g("careu.out");
  7. int F[26];
  8.  
  9. bool palindrom(char s[],int L)
  10. {
  11. for(int i=0;i<L/2;++i)
  12. if(s[i]!=s[L-1-i])
  13. return false;
  14. return true;
  15. }
  16.  
  17. int puncte(char s[])
  18. {
  19. int p=0,n=strlen(s);
  20. if(n%2)
  21. n=n/2+1;
  22. else
  23. n=n/2;
  24. for(int i=0;i<n;++i)
  25. if(F[s[i]-'A']==0)
  26. F[s[i]-'A']=1,p+=(int)s[i];
  27. return p;
  28. }
  29.  
  30. int main()
  31. {
  32. int n;
  33. f>>n;
  34. char s[Nmax],a[Nmax][Nmax],b[Nmax*25][Nmax];
  35. for(int i=0;i<n;++i)
  36. {
  37. f.get();
  38. f.get(s,51);
  39. for(int j=0;j<n;++j)
  40. a[i][j]=s[j];
  41. }
  42. int c;
  43. f>>c;
  44. int j,N=0;
  45. unsigned L,Lmax=0;
  46. for(int i=0;i<n;++i)
  47. {
  48. j=0;
  49. while(j<n)
  50. {
  51. L=0;
  52. while(a[i][j]!='.'&&j<n)
  53. s[L++]=a[i][j],++j;
  54. s[L]='\0';
  55. if(L>1&&palindrom(s,L))
  56. {
  57. if(L>Lmax)
  58. Lmax=L;
  59. strcpy(b[N++],s);
  60. }
  61. ++j;
  62. }
  63. }
  64. for(int i=0;i<n;++i)
  65. {
  66. j=0;
  67. while(j<n)
  68. {
  69. L=0;
  70. while(a[j][i]!='.'&&j<n)
  71. s[L++]=a[j][i],++j;
  72. s[L]='\0';
  73. if(L>1&&palindrom(s,L))
  74. strcpy(b[N++],s);
  75. ++j;
  76. }
  77. }
  78. for(int i=0;i<N;++i) /// Sortez
  79. for(int j=i;j<N;++j)
  80. if(strcmp(b[i],b[j])==1)
  81. swap(b[i],b[j]);
  82. int k=0;
  83. if(strlen(b[0])==Lmax&&Lmax)
  84. strcpy(a[0],b[0]),++k;
  85. for(int i=1;i<N;++i)
  86. if(strlen(b[i])==Lmax&&strcmp(b[i],b[i-1])!=0)
  87. strcpy(a[k++],b[i]);
  88. N=k;
  89. if(c==1)
  90. {
  91. g<<N<<'\n';
  92. for(int i=0;i<N;++i)
  93. g<<a[i]<<'\n';
  94. }
  95. else
  96. {
  97. int punctaj=0;;
  98. for(int i=0;i<N;++i)
  99. punctaj+=puncte(a[i]);
  100. g<<punctaj<<'\n';
  101. }
  102. return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement