语法题
ABC244 D - Swap Hats
题目链接
https://atcoder.jp/contests/abc244/tasks/abc244_d
解析
- 读题要慢要冷静,不着急,一句一句地读,关键在于\(10^{18}\)是偶数次,所以当恰有一对需要交换的时候是不能实现的
- 3个字符相比较,只有三种情况【三个全相等,一个相等,3个全不等】,要先抽象一下化简问题
- 题目的关键在于读入hh,读字符或字符串一定要输出看一眼
//读入方法一
scanf("%c %c %c\n", &s[1], &s[2], &s[3]);
scanf("%c %c %c", &t[1], &t[2], &t[3]);
//读入方法二
scanf("%c %c %c", &s1, &s2, &s3);
getchar();
scanf("%c %c %c", &t1, &t2, &t3);
Ac代码
点击查看代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 5;
char s[N], t[N];
int main()
{
scanf("%c %c %c\n", &s[1], &s[2], &s[3]);
scanf("%c %c %c", &t[1], &t[2], &t[3]);
int cnt = 0;
for(int i = 1; i <= 3; i ++){
if(s[i] != t[i]) cnt ++;
}
if(cnt == 0 || cnt == 3) puts("Yes");
else if(cnt == 2) puts("No");
return 0;
}

浙公网安备 33010602011771号