列表

详情


NC250844. 初中英格力士阅读

描述

Two integers a,b are given. Please determine which one is bigger (or report that they are equal).

Hint one : this problem can be a problem of Nowcodet April Fools Contest, but can't be a problem of Codeforces April Fools Contest for some reasons.    

Hint tow : k turns to ceo.

Hint three: The problem-setter of this problem is careful so he absolutely makes no stupid typo.

输入描述

The first line contains a positice integer T(1\leq T\leq 10201), the number of test cases.

For each test case, two integers a,b(0\leq a,b\leq 100) are given.

输出描述

If a is bigger, output ">" (without quotes).

If b is bigger, output "<" (without quotes).

Otherwise, output "=" (without quotes).

示例1

输入:

5
1 1
0 100
10 3
21 4
100 32

输出:

=
>
<
=
=

说明:

For the first sample: everyone having their kindergarten finished knows they are equal.

For the second sample: apparently, 0 is the biggest number in all possible input.

For the third sample: it's not hard to see, 3 is bigger.

For the last two samples: why are they equal?

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(g++ 7.5.0) 解法, 执行用时: 26ms, 内存消耗: 424K, 提交时间: 2023-04-01 21:03:53

#include<bits/stdc++.h>
using namespace std;
int bihua[] = {14,1,2,3,5,4,4,2,2,2,2};
int cal(int x){
    if(x == 100)return 7;
    if(x <= 10)return bihua[x];
    int di = x%10, gao = x/10;
    if(di==0)return bihua[gao]+bihua[10];
    if(gao==1)return bihua[10]+bihua[di];
    return bihua[di]+bihua[gao]+bihua[10];
}
int main()
{
    int tt;
    cin >> tt;
    while(tt--){
        int a, b;
        cin >> a >> b;
        int ca = cal(a), cb = cal(b);
        if(ca > cb)cout << ">\n";
        else if(ca < cb)cout << "<\n";
        else cout << "=\n";
    }
}

C++(clang++ 11.0.1) 解法, 执行用时: 26ms, 内存消耗: 444K, 提交时间: 2023-04-05 09:01:51

#include <bits/stdc++.h>
using namespace std;
const int a[10] = {0, 1, 2, 3, 5, 4, 4, 2, 2, 2};
int cal(int x) {
    if (x == 0) return 13;
    if (x == 100) return 7;
    if (x / 10 > 1) return a[x / 10] + 2 + a[x % 10];
    if (x >= 10) return 2 + a[x % 10];
    return a[x];
}
int main() {
    int n, x, y;
    cin >> n;
    while (n--) {
        cin >> x >> y;
        if (cal(x) > cal(y)) cout << ">" << endl;
        else if (cal(x) < cal(y)) cout << "<" << endl;
        else cout << "=" << endl;
    }
    return 0;
}

Python3 解法, 执行用时: 107ms, 内存消耗: 4624K, 提交时间: 2023-04-04 22:09:48

bh = [13, 1, 2, 3, 5, 4, 4, 2, 2, 2, 2]

def h(x: int) -> int:
    if x <= 10:
        return bh[x]
    if x == 100:
        return 7
    if x % 10 == 0:
        return bh[x // 10] + 2
    if x <= 20:
        return bh[x % 10] + 2
    return bh[x // 10] + bh[x % 10] + 2

T = int(input())
for _ in range(T):
    a, b = map(int, input().split())
    ta, tb = h(a), h(b)
    if ta > tb:
        print('>')
    elif ta < tb:
        print('<')
    else:
        print('=')

上一题