题解 | #数字反转#简单判断一下就行
数字反转
https://www.nowcoder.com/practice/2687c5c174cb4f938bdae01f0a19490c
//C++版代码 #include <iostream> using namespace std; int reverseNum(int x) { int ret = 0; while (x) { ret = ret * 10 + x % 10; x /= 10; } return ret; } int main() { int a, b; while (cin >> a >> b) { if (reverseNum(a) + reverseNum(b) == reverseNum(a + b)) cout << a + b << endl; else cout << "NO" << endl; } return 0; } //Java版代码 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNextInt()) { int a = sc.nextInt(); int b = sc.nextInt(); if (reverseNum(a) + reverseNum(b) == reverseNum(a + b)) System.out.println(a + b); else System.out.println("NO"); } } private static int reverseNum(int x) { return Integer.parseInt(new StringBuilder(Integer.toString(x)).reverse().toString()); } } #Python版代码 while True: try: a, b = input().split() print(int(a) + int(b) if int(a[::-1]) + int(b[::-1]) == int(str(int(a) + int(b))[::-1]) else 'NO') except: break