还是太弱了
网赛三人睡了两道
A巨水,就不说了,J题写了三遍都没写出来,最后搜了题解,果断重写了main函数中的读取字符串那一段(开始时一个字符一个字符的读,感觉读取字符串总是有点问题,后来果断换成string了,感觉对了,现在zoj挂了,明天提交看看),
开始写的读取的那一段:
int main()
{
freopen("C:/Users/Admin/Desktop/input.txt", "r", stdin);
int T;
cin >> T;
getchar();
while(T--)
{
string s;
while((c = getchar()) != '\n' )
{
if(!(('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))) continue;
//if(c == '\n') break;
else
{
s += c;
}
}
//getchar();
// if(ABABA(s) || ABABCAB(s)) printf("Yes\n");
// else printf("No\n");
cout << s.size() << " " << s << endl;
}
return 0;
}
上面读取手动读入可以,没问题,用了freopen就出错,我怀疑会影响到oj上的评判,所以用string重写了:
int main()
{
//freopen("C:/Users/Administrator/Desktop/input.txt", "r", stdin);
int T;
cin >> T;
while(T--)
{
string a, s;
cin >> a;
int len = a.size();
for(int i = 0; i < len; i++)
{
if(('a' <= a[i] && a[i] <= 'z')||('A'<=a[i]&&a[i]<='Z'))
{
s += a[i];
}
}
//cout << s << endl;
if(ABABA(s) || ABABCAB(s)) printf("Yes\n");
else printf("No\n");
//cout << s.size() << " " << s << endl;
}
return 0;
}
附上最终代码,还是wa了,以后再看看哪里错了吧,网上搜了题解,测了别人的样例都过了,哎,rp问题
//@auther Yang Zongjun
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
using namespace std;
#define PI acos(-1.0)
#define EPS 1e-8
const int MAXN = 55;
const int INF = 2100000000;
char A[MAXN], B[MAXN], C[MAXN], c;
bool ABABCAB(string str)
{
bool flag = false;
int len = str.size();
for(int i = 1; i <= (len / 3); i++)//A
{
for(int j = i; j <= (len / 2); j++)//B
{
//for(int k = 0; k <= (len - 4); k++)//C
//{
string A1,A2, B1, B2;
for(int m = 0; m < i; m++)
{
A1 += str[m];
}
for(int m = i; m <= j; m++)
{
B1 += str[m];
}
//cout << A1 << " " << B1 << endl;
int lenA1 = A1.size(), lenB1 = B1.size();
int cnt = lenA1 + lenB1;
//cout << cnt << endl;
int t = cnt;cnt += lenA1;
for(int m = t; m < cnt; m++)
{
A2 += str[m];
}//cout << cnt << endl;
t = cnt;cnt += lenB1;
for(int m = t; m < cnt; m++)
{
B2 += str[m];
}
string C;
for(int k = cnt; k <= (len - 2); k++)//C
{
C += str[k];
t = k + 1;cnt = k + 1 + lenA1;
string A3, B3;
for(int m = t; m < cnt; m++)
{
A3 += str[m];
}
t = cnt;cnt += lenB1;
for(int m = t; m < len; m++)
{
B3 += str[m];
}
int lenC = C.size();
//cout << cnt << endl;
if(((lenA1*3+lenB1*3+lenC) == len) && (A1 == A2 && A2 == A3 && A1 == A3) && (B1 == B2 && B1 == B3 && B2 == B3) && (A1 != B1) && (A1 != C) && (B1 != C))
{
//cout << A1<<"_" << A2<<"_" << A3<<"_" << B1<<"_"<<B2<<"_"<< C<<"_"<< endl;
return true;
}
}
//}
}
}
return false;
}
bool ABABA(string str)
{
bool flag = false;
int len = str.size();
for(int i = 1; i <= (len / 3); i++)//A
{
for(int j = 1; j <= (len / 2); j++)//B
{
//for(int k = 0; k <= (len - 4); k++)//C
//{
string A1,A2, A3, B1, B2, C;
for(int m = 0; m < i; m++)
{
A1 += str[m];
}
for(int m = i; m <= j; m++)
{
B1 += str[m];
}
//cout << A1 << " " << B1 << endl;
int lenA1 = A1.size(), lenB1 = B1.size();
int cnt = lenA1 + lenB1;
//cout << cnt << endl;
int t = cnt;cnt += lenA1;
for(int m = t; m < cnt; m++)
{
A2 += str[m];
}//cout << cnt << endl;
t = cnt;cnt += lenB1;
for(int m = t; m < cnt; m++)
{
B2 += str[m];
}
t = cnt;cnt += lenA1;
for(int m = t; m < len; m++)
{
A3 += str[m];
}
//cout << cnt << endl;
//cout << A1 << " " << B1 << " " << C << endl;
if((lenA1 * 3 + lenB1 * 2 == len) && (A1 == A2 && A2 == A3 && A1 == A3) && (B1 == B2) && (A1 != B1))
{
return true;
}
//}
}
}
return false;
}
int main()
{
freopen("C:/Users/Administrator/Desktop/input.txt", "r", stdin);
int T;
cin >> T;
while(T--)
{
string a, s;
cin >> a;
int len = a.size();
for(int i = 0; i < len; i++)
{
if(('a' <= a[i] && a[i] <= 'z')||('A'<=a[i]&&a[i]<='Z'))
{
s += a[i];
}
}
//cout << s << endl;
//cout << s.size() << " " << s << endl;
if(ABABA(s) || ABABCAB(s)) printf("Yes\n");
else printf("No\n");
}
return 0;
}