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

被折叠的 条评论
为什么被折叠?



