fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define SET(a) memset(a,-1,sizeof(a))
  5. #define CLR(a) memset(a,0,sizeof(a))
  6. #define PI acos(-1.0)
  7.  
  8. #define MOD 1000000007
  9. #define MX 100010
  10.  
  11. string reverse (string s)
  12. {
  13. string result="";
  14. int sl=s.length();
  15. for (int i=0; i<sl; i++)
  16. result = s[i] + result ;
  17. return result;
  18. }
  19.  
  20. int main()
  21. {
  22. int tc,kk=1, n, r, sl;
  23. string s;
  24.  
  25. while(cin>>r && r)
  26. {
  27. cin>>n;
  28. getline(cin,s);
  29. sl=s.length();
  30. int pos=0;
  31. while(s[pos]==' ') pos++;
  32.  
  33. string s1="";
  34. string s2="";
  35. if(s[pos]=='"')
  36. {
  37. pos++;
  38. while(s[pos]!='"')
  39. {
  40. s1+=s[pos];
  41. pos++;
  42. }
  43. }
  44. else
  45. {
  46. while(s[pos]!=' ')
  47. {
  48. s1+=s[pos];
  49. pos++;
  50. }
  51. }
  52. pos=sl-1;
  53. while(s[pos]==' ') pos--;
  54. if(s[pos]=='"')
  55. {
  56. pos--;
  57. while(s[pos]!='"')
  58. {
  59. s2+=s[pos];
  60. pos--;
  61. }
  62. }
  63. else
  64. {
  65. while(s[pos]!=' ')
  66. {
  67. s2+=s[pos];
  68. pos--;
  69. }
  70. }
  71. s2=reverse(s2);
  72.  
  73. for(int i=0;i<s1.length();i++)
  74. if(s1[i]>='A' && s1[i]<='Z')
  75. s1[i]=tolower(s1[i]);
  76. for(int i=0;i<s2.length();i++)
  77. if(s2[i]>='A' && s2[i]<='Z')
  78. s2[i]=tolower(s2[i]);
  79. cout<<kk++<<". ";
  80. if(((r-1)/n)%2==0)
  81. cout<<s1<<endl;
  82. else cout<<s2<<endl;
  83.  
  84. }
  85. return 0;
  86. }
Success #stdin #stdout 0s 3300KB
stdin
Standard input is empty
stdout
Standard output is empty