Guest User

Untitled

a guest
Jul 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. /*
  2. ID : bristy11
  3. LANG : C++
  4. TASK : calfflac
  5. */
  6. //Bristy Sikder Loves U
  7. # include <iostream>
  8. # include <stdio.h>
  9. # include <map>
  10. # include <cstring>
  11. # include <vector>
  12. using namespace std;
  13.  
  14. int main()
  15. {
  16. //data structures
  17. int a,b,c,size,alph,check;
  18. char line[40000]; // the main string
  19. char str[85];
  20. char smlet[]={"abcdefghijklmnopqrstuvwxyz"};
  21. char caplet[]={"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
  22. vector <char> pal;
  23. map<int,int>tag;
  24.  
  25. freopen("calfflac.in","r",stdin);
  26. freopen("calfflac.out","w",stdout);
  27.  
  28. //input
  29. size=0;
  30. while (gets(str)!=NULL){
  31. int k;
  32. k=strlen(str);
  33. for(b=0;b<k;b++) line[size+b]=str[b];
  34. line[size+k]=1;
  35. size+=k+1;
  36. //cout << line << "\n";
  37. }
  38. /*for(int i=0;i<size;i++)
  39. {
  40. if(line[i]==1)
  41. printf("\n");
  42. else
  43. printf("%c",line[i]);
  44. }*/
  45.  
  46.  
  47. // printf(":\n");
  48. //sorting out the letters
  49. alph=0;
  50. for(a=0;a<size;a++){
  51. for(b=0;b<strlen(smlet);b++){
  52. if(line[a]==smlet[b]) {
  53. pal.push_back(caplet[b]);
  54. tag[alph]=a;
  55. alph++;
  56. //cout << line[a];
  57. }
  58. }
  59. for(b=0;b<strlen(caplet);b++){
  60. if(line[a]==caplet[b]) {
  61. pal.push_back(caplet[b]);
  62. tag[alph]=a;
  63. alph++;
  64. //cout << line[a];
  65. }
  66. }
  67. }
  68. //for(a=0;a<alph;a++) cout << pal[a] << " " << a << " ";
  69. //cout << endl;
  70.  
  71. //processing
  72. int finlen=0;
  73. int finbeg=0;
  74. int finend=0;
  75. for(a=0;a<alph-1;a++){
  76. for(b=min(a+1999,alph-1);b>=max(a+1,a+finlen);b--){ // b<=size-1; b>finlen;
  77. //palindrome check
  78. //cout << a << " " << b << endl;
  79. check=0;
  80. for(c=0;c<=(b-a)/2;c++){
  81. //cout << pal[a+c] << pal[b-c] << " " <<a+c<< " " << b-c << endl;
  82. if(pal[a+c]!=pal[b-c]) {
  83. check=1;
  84. break;
  85. }
  86. }
  87. if(check==1) continue;
  88. else {
  89. finlen=b-a+1;
  90. finbeg=tag[a];
  91. finend=tag[b];
  92. //cout << finlen << endl;
  93. //for(a=finbeg;a<=finend;a++) cout << line[a];
  94. //cout << endl;
  95. break;
  96. }
  97. }
  98. }
  99.  
  100. //results
  101. cout << finlen << endl;
  102.  
  103. for(a=finbeg;a<=finend;a++)
  104. {
  105. if(line[a]==1) printf("\n");
  106. else cout << line[a];
  107.  
  108. }
  109. printf("\n");
  110. return 0;
  111. }
Add Comment
Please, Sign In to add comment