Advertisement
a53

datapal

a53
Feb 20th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <fstream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int pal(char s[])
  6. {
  7. int l=0;
  8. int h=strlen(s)-1;
  9. while(h>l)
  10. {
  11. if(s[l++]!=s[h--])
  12. return 0;
  13. }
  14. return 1;
  15. }
  16.  
  17. int main()
  18. {
  19. ifstream f("datapal.in");
  20. int n,N=0,sec,secmax;
  21. char s[9],F[101];
  22.  
  23. f>>n;
  24. f.get();
  25. for(int i=1;i<=n;++i)
  26. {
  27. f.getline(s,9);
  28. if(pal(s))
  29. {
  30. ++N;
  31. sec=(s[4]-'0')*10+s[5]-'0';
  32. ++F[sec];
  33. if(F[sec]>secmax)
  34. secmax=F[sec];
  35. }
  36. }
  37. f.close();
  38. ofstream g("datapal.out");
  39. if(N==0)
  40. g<<"NU EXISTA DATE PALINDROM\n";
  41. else
  42. {
  43. g<<N<<'\n';
  44. for(int i=0;i<100;++i)
  45. if(F[i]==secmax)
  46. g<<i+1<<' ';
  47. }
  48. g.close();
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement