栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

A. Spring Couplets

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

A. Spring Couplets

A. Spring Couplets

这题就是看对联押不押韵,拼音有四个音调,第一声和第二声为平声,第三声和第四声为仄声。
具体判断规则为:
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;
		}
		//输出每个字的音调
		
//cout<< endl;
	}

}

int main() {

	test01();
	return 0;
}

注意输出格式就好,我用的visual studio,不知道为啥显示.exe文件无法写入,把电脑重启才好。时间长没做题,这题卡我输出格式卡了四十分钟,习惯加一个换行,真的吐了。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/852059.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号