语法题

ABC244 D - Swap Hats

题目链接
https://atcoder.jp/contests/abc244/tasks/abc244_d

解析

  • 读题要慢要冷静,不着急,一句一句地读,关键在于1018是偶数次,所以当恰有一对需要交换的时候是不能实现的
  • 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;
}

posted @   小菜珠的成长之路  阅读(30)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示