solution-at4703

题解 AT4703 【Red or Blue】

原题

来介绍一下三元运算符:

A ? B : C

如果表达式A为真,则执行B语句,否则执行C语句。

其作用就相当于:

if(A)
{
	B;
}
else
{
	C;
}

例如1 + 1 > 2 ? puts("I AK IOI") : puts("qwq");

将会输出qwq

那么此题代码就可以变得极简。

代码

#include<iostream>
using namespace std;
int n,r,b; // r统计红,b统计蓝
int main()
{
	cin >> n;
	getchar(); // 把换行读掉
	while(n--)
		getchar() == 'R' ? ++r : ++b;
	r > b ? puts("Yes") : puts("No");
    return 0;
}
posted @ 2024-03-06 16:55  iorit  阅读(7)  评论(0)    收藏  举报