标签:bre style mes -- while 通过 标识 cout ascii
‘\0‘ : 字符串结束标识符,也是空字符,ascii码为00
APAT-YES
APAATA-NO,因为c为空字符,即字符串结束。
APAATAA-NO
#include <iostream> using namespace std; int main() { int n,i; int sign = -1; cin>>n; char str[101]; while(n) { cin>>str; i = 0; int c_p = 0, c_t = 0; while(str[i]!=‘\0‘) { if(str[i]!=‘P‘&&str[i]!=‘A‘&&str[i]!=‘T‘) { sign = 0; break; } if(str[i] == ‘P‘) c_p++; else if(str[i] == ‘T‘) c_t++; i++; } if(!(c_p==1&&c_t==1)) sign = 0; int p = -1,t = -1; while(sign!=0) { for(int k=i-1;k>=0;k--) { if(str[k] == ‘P‘) p = k; else if(str[k] == ‘T‘) t = k; } int distance = t-p; if(p==0&&t==i-1&&distance>=2) { sign=1; break; } else if(distance==2) { sign=1; break; } else if(distance<=1) { sign=0; break; } else if(i-1-(distance-2)*p>t) { sign=1; break; } else { sign=0; break; } } if(sign == 0) cout<<"NO"<<endl; else if(sign == 1) cout<<"YES"<<endl; sign = -1; n--; } return 0; }
标签:bre style mes -- while 通过 标识 cout ascii
原文地址:https://www.cnblogs.com/QRain/p/12217333.html