-
题目
-
思路
- 对读入的每个字符串分别处理,记录其中p、t、其他字符的个数,以及p、t的位置,比较左侧a的个数 * 中间a的个数是否等于右侧a的个数
-
代码
#include <iostream> #include <string> using namespace std; int main(){ int n; cin>>n; string s; for(int i=0;i<n;i++){ cin>>s; int p_num=0,other=0,t_num=0; //记录不同字符个数 int p_loc=-1,t_loc=-1; for(int j=0;j<s.length();j++){ if(s[j]=='P'){ p_num++; p_loc=j; }else if(s[j]=='T'){ t_num++; t_loc=j; }else if(s[j]!='A'){ other++; } } int l=p_loc; int m=t_loc-p_loc-1; int r=s.length()-1-t_loc; if(other!=0||p_num!=1||t_num!=1||t_loc-p_loc<2){ //答案错误 cout<<"NO"<<endl; continue; } if(l*m==r){ cout<<"YES"<<endl; }else{ cout<<"NO"<<endl; } } return 0; }