标签:
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 709 Accepted Submission(s): 294
#include<stdio.h> #include<string.h> #include<string> #include<iostream> #include<algorithm> using namespace std; #define N 1234567 int n,a[N],flag,ans,cnt; int main() { int T;cin>>T; for(int tt = 1; tt <= T; tt++) { cnt = flag = 0; string str = ""; cin>>str; if(str.size() == 1) { flag = 1; } else if(str.size() == 2) { if(str == "ff") flag = 0; else flag = 1; } else if(str[str.size()-1] == ‘c‘) { if(str[0] == ‘c‘ || str[1] == ‘c‘) flag = 1; } else if(str[0] == ‘c‘) { if(str[str.size()-2] == ‘c‘) flag = 1; } for(int i = 0; flag != 1 && i < str.size(); i++) { if(str[i] != ‘c‘ && str[i] != ‘f‘) { flag = 1; break; } if(str[i] == ‘c‘) { if(i+1 < str.size() && str[i+1] == ‘c‘) { flag = 1; break; } if(i+2 < str.size() && str[i+2] == ‘c‘) { flag = 1; break; } flag = 2; cnt++; } } if(flag == 1 && str.size() == 1) { if(str[0] == ‘f‘) ans = 1; else ans = -1; } else if(flag == 1 || str.size() == 0) { ans = -1; } else if(flag == 0) { ans = (str.size() + 1) / 2; } else { ans = cnt; } printf("Case #%d: %d\n", tt, ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/wmxl/p/4829299.html