fork download
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<string>
  4. #include<string.h>
  5. #include<algorithm>
  6. #include<math.h>
  7. using namespace std;
  8. const int Length =(int)2*1e6;
  9. bool is_subsequence(string,string);
  10. bool isDoubleString(string);
  11. int main(){
  12. int D,tempD,i,c;
  13. bool output[Length/2];
  14. cin>>D;
  15. getchar();
  16. tempD=0;
  17. while(D>0){
  18.  
  19. char str[Length];
  20. for(i=0;(c=getchar())!='\n';i++)str[i]=c;
  21. str[i]='\0';
  22. D--;
  23. if(isDoubleString(string(str))){
  24. output[tempD++]=true;
  25. }else{
  26. output[tempD++]=false;
  27. }
  28. }
  29. i=0;
  30. while(tempD>0){
  31. if(output[i++]){
  32. cout<<"true"<<endl;
  33. }else{
  34. cout<<"false"<<endl;
  35. }
  36.  
  37. tempD--;
  38. }
  39. return 0;
  40. }
  41. bool isDoubleString(string input){
  42. int n=input.size();
  43. if(n%2==0){
  44. return is_subsequence(input.substr(0,(n/2)),input.substr(n/2));
  45. }else if(n>1){
  46. return is_subsequence(input.substr(0,(n/2)+1),input.substr((n/2)+1))||is_subsequence(input.substr(0,n/2),input.substr(n/2));
  47. }
  48. else{
  49. return false;
  50. }
  51.  
  52. }
  53. bool is_subsequence(string a,string b){
  54. int i=0;int j=0;
  55. if(a.size()>b.size()){
  56. for(;i<a.size()&&j<b.size();++i){
  57. if(a[i]==b[j]){
  58. j++;
  59. }
  60. }
  61. return (j==b.size());
  62. }else{
  63. for(;i<b.size()&&j<a.size();++i){
  64. if(a[j]==b[i]){
  65. j++;
  66. }
  67. }
  68. return (j==a.size());
  69. }
  70. }
  71.  
Success #stdin #stdout 0s 6268KB
stdin
Standard input is empty
stdout
Standard output is empty