码迷,mamicode.com
首页 > 其他好文 > 详细

1003 我要通过!

时间:2018-08-22 01:12:57      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:防止   name   turn   ble   end   stream   set   cin   for   

题目链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805323154440192

题解:

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<string>
 4 using namespace std;
 5 
 6 int main(){
 7     int n;
 8     cin>>n;
 9     getchar();
10     string *str = new string[n];
11     for(int i=0;i<n;i++)
12         getline(cin,str[i]);
13     for(int i=0;i<n;i++){
14         if((str[i][0]==P&&str[i][1]==A&&str[i][2]==T)&&(str[i].size()==3)){
15             cout<<"YES"<<endl;
16         }
17         else if((str[i][0]==P&&str[i][1]==A&&str[i][2]==A&&str[i][3]==T)&&(str[i].size()==4)){
18             cout<<"YES"<<endl;
19         }
20         else{
21             int nP=0,nA=0,nT=0;
22             bool flag=false;
23             for(int j=0;j<str[i].size();j++){
24                 if(str[i][j]==P) nP++;
25                 if(str[i][j]==A) nA++;
26                 if(str[i][j]==T) nT++;
27             }
28             if(nP==1&&nT==1&&nA>0&&nP+nA+nT==str[i].size()) flag=true;//nA>0是为了防止出现PT这种情况
29             if(!flag){
30                 cout<<"NO"<<endl;
31             }
32             else{
33                 int len_l=0,len_m=0,len_r=0,j=0;
34                 for(j=0;j<str[i].size();j++){
35                     if(str[i][j]==P) {
36                         len_l=j;
37                         break;
38                     }
39                 }
40                 j++;
41                 while(str[i][j]!=T){
42                     len_m++;
43                     j++;
44                 }
45                 j++;
46                 len_r=str[i].size()-j;
47                 if(len_l*len_m==len_r) cout<<"YES"<<endl;
48                 else cout<<"NO"<<endl;
49             }
50         }
51     }
52     return 0;
53 }

 

1003 我要通过!

标签:防止   name   turn   ble   end   stream   set   cin   for   

原文地址:https://www.cnblogs.com/Gzu_zb/p/9515294.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!