fork download
  1. /*
  2.   Name:
  3.   Copyright: DHKHTN - DHQGHN
  4.   Author: Nguyen Dinh Nhat
  5.   Date: 26/07/10 21:40
  6.   Description: COUNTPL https://v...content-available-to-author-only...j.pl/problems/COUNTPL/
  7. */
  8.  
  9.  
  10. #include <stdio.h>
  11.  
  12. #include <stdlib.h>
  13. #include <string.h>
  14.  
  15. #define TI freopen("test.inp","rt",stdin)
  16.  
  17. #define FOR(i,a,b) for(int i=a;i<=b;i++)
  18. #define FORD(i,a,b) for(int i=a;i>=b;i--)
  19. #define REP(i,n) for(int i=0;i<n;i++)
  20.  
  21. void COUNTPL (char a[])
  22. {
  23. int n=strlen (a),i=0,j=n-1,count=0,k=0,l=n-1;
  24. //n: Do dai xau
  25. //i: vi tri hien tai
  26. //j: vi tri j de tim chuoi paalindrome max
  27. //k: biet tam de i tang
  28. //count: dem so chuoi palindrome
  29. while (i<n)
  30. {
  31. while (j>=i) //
  32. {
  33. while (a[i]!=a[j]) j--; // tim vi tri j ma a[i]=a[j]
  34. //kiem tra chuoi bat dau tu i ket thuc o j co phai la chuoi palindrome
  35. k=i+1;
  36. l=j-1;
  37. while (a[k]==a[l]&&k<l){ k++; l--; }
  38. if (k==l||k-l==1||i==j){ count++; i=j+1; j=n-1; break;}
  39. j--;
  40. }
  41. }
  42. printf ("%d\n",count);
  43. }
  44.  
  45. //#include <conio.h>
  46. int main ()
  47. {
  48. // TI;
  49. char a[300];
  50.  
  51. gets (a);
  52. COUNTPL (a);
  53. // getch ();
  54. return 0;
  55. }
  56.  
stdin
bobseesanna
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:51: warning: ignoring return value of ‘char* gets(char*)’, declared with attribute warn_unused_result
/home/dc5eOn/ccyzQJDh.o: In function `main':
prog.cpp:(.text+0x19e): warning: the `gets' function is dangerous and should not be used.
stdout
3