NC250844. 初中英格力士阅读
描述
输入描述
The first line contains a positice integer , the number of test cases.For each test case, two integers are given.
输出描述
If is bigger, output "" (without quotes).If is bigger, output "" (without quotes).Otherwise, output "" (without quotes).
示例1
输入:
5 1 1 0 100 10 3 21 4 100 32
输出:
= > < = =
说明:
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('=')