转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
必须是连续的字母。。。被坑了
1 //##################### 2 //Author:fraud 3 //Blog: http://www.cnblogs.com/fraud/ 4 //##################### 5 #include <iostream> 6 #include <sstream> 7 #include <ios> 8 #include <iomanip> 9 #include <functional> 10 #include <algorithm> 11 #include <vector> 12 #include <string> 13 #include <list> 14 #include <queue> 15 #include <deque> 16 #include <stack> 17 #include <set> 18 #include <map> 19 #include <cstdio> 20 #include <cstdlib> 21 #include <cmath> 22 #include <cstring> 23 #include <climits> 24 #include <cctype> 25 using namespace std; 26 #define XINF INT_MAX 27 #define INF 0x3FFFFFFF 28 #define MP(X,Y) make_pair(X,Y) 29 #define PB(X) push_back(X) 30 #define REP(X,N) for(int X=0;X<N;X++) 31 #define REP2(X,L,R) for(int X=L;X<=R;X++) 32 #define DEP(X,R,L) for(int X=R;X>=L;X--) 33 #define CLR(A,X) memset(A,X,sizeof(A)) 34 #define IT iterator 35 typedef long long ll; 36 typedef pair<int,int> PII; 37 typedef vector<PII> VII; 38 typedef vector<int> VI; 39 int vis[1010]; 40 int num[1010]; 41 int main() 42 { 43 ios::sync_with_stdio(false); 44 string s; 45 while(cin>>s){ 46 int len=s.length(); 47 CLR(vis,0); 48 CLR(num,0); 49 int ans=1; 50 int cs=0; 51 int k=len/3; 52 if(k*3!=len)ans=0;if(ans){ 53 char str=s[0]; 54 for(int i=0;i<k;i++){ 55 if(s[i]!=str)ans=0; 56 } 57 str=s[k]; 58 if(s[k]==s[k-1])ans=0; 59 for(int i=k;i<len-k;i++){ 60 if(s[i]!=str)ans=0; 61 } 62 str=s[len-k]; 63 if(str==s[len-k-1])ans=0; 64 if(str==s[0])ans=0; 65 for(int i=len-k;i<len;i++){ 66 if(s[i]!=str)ans=0; 67 } 68 } 69 if(ans)cout<<"YES"<<endl; 70 else cout<<"NO"<<endl; 71 } 72 73 return 0; 74 }