这题就是看对联押不押韵,拼音有四个音调,第一声和第二声为平声,第三声和第四声为仄声。
具体判断规则为:
1.每一个字的平(仄)声对应另一行的仄(平)声。
2.第一行的最后一个音调必须为仄声,第二行的最后一个音调必须为平声。
#include
#include
#include
using namespace std;
void test01() {
int n;
cin >> n;
char s[200];
char a[300];
while (n--) {
int flag = 1;
memset(a, 0, sizeof(a));
memset(s, 0, sizeof(s));
int len;
int t;
cin >> t;
for (int i = 0; i < 2 * t; i++) {
cin >> s;
int len = strlen(s);
//cout << len << endl;
a[i + 1] = s[len - 1];//将每个字的音调提取出来
memset(s, 0, sizeof(s));
}
if (a[t] <= '2' || a[2 * t] >= '3') {
cout << "NO" << endl;
continue;
}
for (int i = 1; i <= t; i++) {
//cout << "测试" << endl;
if (a[i] <= '2' && a[i + t] >= '3') {
flag = 1;
//cout <<"条件1:"<< a[i] << " " << a[i + t] << endl;
}
else if (a[i] >= '3' && a[i + t] <= '2') {
flag = 1;
//cout <<"条件2:"<< a[i] << " " << a[i + t] << endl;
}
else {
flag = 0;
//cout << a[i] << " " << a[i + t] << endl;
break;
}
}
if (flag == 1) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
//输出每个字的音调
/*for (int i = 1; i <= 2 * t; i++) {
cout << a[i] << " ";
if ((i == t) || (i == 2 * t)) {
cout << endl;
}
}*/
//cout<< endl;
}
}
int main() {
test01();
return 0;
}
注意输出格式就好,我用的visual studio,不知道为啥显示.exe文件无法写入,把电脑重启才好。时间长没做题,这题卡我输出格式卡了四十分钟,习惯加一个换行,真的吐了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)