标签:for turn 问题 pre print == col strlen div
#include <cstdio> #include <cstring> int main() { int n; scanf("%d", &n); // 之前一直用c++过不了,因为会有空格的关系,所以改用了scanf; while (n--) { char s[110]; int np = 0, lp = 0, nt = 0, lt = 0, other = 0; scanf("%s", s); int len = strlen(s); for (int i = 0; i < len; i++) { if (s[i] == ‘P‘) { np++; lp = i; } else if (s[i] == ‘T‘) { nt++; lt = i; } else if (s[i] != ‘A‘) // 一种很巧妙的设置,可以控制其他符号的问题 other++; } if ((np != 1) || (nt != 1) || (lt - lp <= 1) || (other != 0)) { //利用数组下标与平时数字的差 printf("NO\n"); continue; } int x = lp, y = lt - lp - 1, z = len - lt - 1; if (x * y == z) printf("YES\n"); else printf("NO\n"); } return 0; }
标签:for turn 问题 pre print == col strlen div
原文地址:https://www.cnblogs.com/Hk456/p/10753337.html