HDU2051-2060题解

本文解析了两个算法题目,一是判断两数是否相等的简单算法,二是处理字符与数值运算的问题。通过代码示例,展示了如何在C++中使用条件运算符和字符数组进行操作。

2051 Bitset

2054 A == B ?

  • Problem Description
    Give you two numbers A and B, if A is equal to B, you should print “YES”, or print “NO”.
  • Input
    each test case contains two numbers A and B.
  • Output
    for each case, if A is equal to B, you should print “YES”, or print “NO”.
  • Sample Input
    1 2
    2 2
    3 3
    4 3
    
  • Sample Output
    NO
    YES
    YES
    NO
    

下面的两种写法都是错误的。

#include <cstdio>
int main() {
	int a, b;
	while (~scanf("%d%d", &a, &b)) {
		printf("%s\n", a == b ? "YES" : "NO");
	}
	return 0;
}
#include <string>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
	string s1, s2;
	while (cin >> s1 >> s2) {
		printf("%s\n", s1 == s2 ? "YES" : "NO");
	}
	return 0;
}

2055 An easy problem

#include <cstdio>
int main() {
	int n, p;
	scanf("%d\n", &n);
	char c;
	int letters[128] = {0};
	for (char i = 'A'; i <= 'Z'; i++) letters[i] = (i - 'A' + 1);
	for (char i = 'a'; i <= 'z'; i++) letters[i] = ('a' - i - 1); 
	while (n--) {
		scanf("%c %d\n", &c, &p);
		printf("%d\n", letters[c] + p);
	}
	return 0;
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

memcpy0

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值