pat 1003 我要通過!(20)
阿新 • • 發佈:2018-07-08
裁判 pro 組成 title brush true get char s hat ”的。
1003 我要通過!(20)(20 分)
“答案正確”是自動判題系統給出的最令人歡喜的回復。本題屬於PAT的“答案正確”大派送 —— 只要讀入的字符串滿足下列條件,系統就輸出“答案正確”,否則輸出“答案錯誤”。
得到“答案正確”的條件是:
1. 字符串中必須僅有P, A, T這三種字符,不可以包含其它字符;\
- 任意形如 xPATx 的字符串都可以獲得“答案正確”,其中 x 或者是空字符串,或者是僅由字母 A 組成的字符串;\
- 如果 aPbTc 是正確的,那麽 aPbATca 也是正確的,其中 a, b, c 均或者是空字符串,或者是僅由字母 A 組成的字符串。
現在就請你為PAT寫一個自動裁判程序,判定哪些字符串是可以獲得“答案正確
輸入格式: 每個測試輸入包含1個測試用例。第1行給出一個自然數n (<10),是需要檢測的字符串個數。接下來每個字符串占一行,字符串長度不超過100,且不包含空格。
輸出格式:每個字符串的檢測結果占一行,如果該字符串可以獲得“答案正確”,則輸出YES,否則輸出NO。
輸入樣例:
8
PAT
PAAT
AAPATAA
AAPAATAAAA
xPATx
#include<stdio.h> #include<string.h> int main() { char s[110]; int pos_p,pos_t,count_p,count_a,count_t,n; scanf("%d\n",&n); while(n--){ pos_p=pos_t=count_p=count_a=count_t=0; gets(s); for(int i=0;i<strlen(s);i++){ if(s[i] == ‘P‘){ count_p++; pos_p = i; }else if(s[i] == ‘A‘){ count_a++; }else if(s[i] == ‘T‘){ count_t++; pos_t = i; } } if(count_p+count_a+count_t<strlen(s)|| count_p>1 || count_t>1 || pos_p*(pos_t-pos_p-1)!=strlen(s)-pos_t-1 || pos_t-pos_p<=1) printf("NO\n"); else printf("YES\n"); } }
PT Whatever APAAATAA
輸出樣例:
YES
YES
YES
YES
NO
NO
NO
NO
pat 1003 我要通過!(20)