Advertisement
JeffreyHo

B - 子字串

Aug 6th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6.     int t;
  7.     cin >> t;
  8.     while (t--) {
  9.         string s, t = "meteor";
  10.         cin >> s;
  11.         bool ans = 0;
  12.         for (int i = 0; i < 6; i++) {
  13.             bool ok = 1;
  14.             for (int j = 0; j < s.length(); j++) if (s[j] != t[(j + i) % 6]) ok = 0;
  15.             if (ok) ans = 1;
  16.         }
  17.         if (ans) cout << "Yes\n";
  18.         else cout << "No\n";
  19.     }
  20. }
  21.  
  22. /*
  23. 20
  24. meteor
  25. meter
  26. rm
  27. dcard
  28. e
  29. eorm
  30. eteo
  31. helloworld
  32. meor
  33. meteormeteormeteormeteormeteormeteormeteormeteorme
  34. meteormeteormeteormeteormeteormeteormeteormeteormt
  35. eormeteormeteormeteormeteormeteormeteormeteormete
  36. meteormeteormeteormeormeteor
  37. ormeteormeteormeteormeteormeeteormeteor
  38. metro
  39. meteorrrrrrrrrrrrrrrrrrr
  40. roetem
  41. teormeteormet
  42. a
  43. qwertyuiopasdfghjklzxcvbnm
  44. */
  45.  
  46. /*
  47. Yes
  48. No
  49. Yes
  50. No
  51. Yes
  52. Yes
  53. Yes
  54. No
  55. No
  56. Yes
  57. No
  58. Yes
  59. No
  60. No
  61. No
  62. No
  63. No
  64. Yes
  65. No
  66. No
  67.  
  68. */
  69.  
  70. /*
  71. //1 - 咻咻冰棒
  72. #include <iostream>
  73. #include <algorithm>
  74. #include <string>
  75. using namespace std;
  76. int main(){
  77.     int T;cin >> T;
  78.     string m = "meteor";
  79.     while(T--){
  80.         string s;cin >> s;
  81.         bool ok = 0;
  82.         for(int i = 0 ; i < 6 ; i++){
  83.             bool tmp = 1;
  84.             for(int j = 0 ; j < s.length(); j++){
  85.                 if(m[(i+j)%6] != s[j])tmp = 0;
  86.             }
  87.             if(tmp){ok = 1;break;}
  88.         }
  89.         ok ? puts("Yes") : puts("No");
  90.     }
  91. }
  92. */
  93.  
  94. /*
  95. //7 - 軟男不是暖男
  96. #include <iostream>
  97. #include <cstring>
  98. using namespace std;
  99.  
  100. int main()
  101. {
  102.     char str[50],correct[10]={'m','e','t','e','o','r'};
  103.     int t;
  104.     cin>>t;
  105.     while(t--)
  106.     {
  107.         cin>>str;
  108.         int index=-1;
  109.         bool ans=true;
  110.         for(int i=0;i<6;i++)
  111.         {
  112.             if(str[0]==correct[i])
  113.             {
  114.                 index=i;
  115.                 break;
  116.             }
  117.         }
  118.         //cout<<index;
  119.         if(index==-1)
  120.         {
  121.             ans=false;
  122.         }
  123.         else
  124.         {
  125.             if(index==1||index==3)
  126.             {
  127.                 if(str[1]=='t')
  128.                     index==1;
  129.                 else if(str[1]=='o')
  130.                     index=3;
  131.                 else if(strlen(str)==1)
  132.                 {
  133.                     ans=true;
  134.                 }
  135.                 else
  136.                 {
  137.                     ans=false;
  138.                 }
  139.             }
  140.             //cout<<index<<endl;
  141.             if(ans==true)
  142.             {
  143.                 for(int i=0;str[i]!='\0';i++,index++)
  144.                 {
  145.                     index%=6;
  146.                     //cout<<index<<endl;
  147.                     if(str[i]!=correct[index])
  148.                     {
  149.                         ans=false;
  150.                     }
  151.                 }
  152.             }
  153.         }
  154.         if(ans==true)
  155.             cout<<"Yes"<<endl;
  156.         else
  157.             cout<<"No"<<endl;
  158.     }
  159. }
  160. */
  161.  
  162. /*
  163. //11 - 莫測
  164. #include <iostream>
  165. #include <algorithm>
  166. #include <vector>
  167. #include <string>
  168. using namespace std;
  169.  
  170. string str;
  171. string cmp;
  172. int main(void){
  173.     int t;
  174.     cin>>t;
  175.     for(int i = 0;i<10;i++)
  176.         cmp += "meteor";
  177.     while(t--){
  178.         str.clear();
  179.         cin>>str;
  180.         cmp.find(str) == string::npos ? cout<<"No\n" : cout<<"Yes\n";
  181.     }
  182. }
  183. */
  184.  
  185. /*
  186. //18 - TNT5080
  187. //唯一錯的一筆是 "roetem" 欸,有點可惜
  188. #include <iostream>
  189.  
  190. using namespace std;
  191.  
  192. int main()
  193. {
  194.     string input,word = "meteormeteormeteormeteormeteormeteormeteormeteormeteormeteor";
  195.     int n,i,j,check;
  196.     cin >> n;
  197.     while(n--)
  198.     {
  199.         cin >> input;
  200.         check = 0;
  201.         for(i=0;i<word.length();i++)
  202.         {
  203.             for(j=0;;j++)
  204.                 if(word[i+j] != input[j])
  205.                     break;
  206.             if(j==input.length())
  207.                 break;
  208.         }
  209.         //cout << "===>" << j << "\n";
  210.         if(j>0)
  211.             cout << "Yes" << "\n";
  212.         else
  213.             cout << "No" << "\n";
  214.     }
  215. }
  216. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement