【思路】:atoi和itoa的使用,注意atoi,三个参数。第一个是要转换的数,第二个是保存在那个字符串中,第三个是什么进制。
【AC代码】:
#include <iostream> #include <algorithm> #include <string> #include <cstdio> #include <cstring> using namespace std; #define MAX 20+2 int reverse_num(int x) { int i = 0; char a[MAX]; itoa(x, a, 10); for (i = 0; i < strlen(a)/2; i++) { char temp = a[i]; a[i] = a[strlen(a)-1-i]; a[strlen(a)-1-i] = temp; } return atoi(a); } int main() { //freopen("in.txt", "r", stdin); int i = 0, sum = 0; int a = 0, b = 0;; cin >> a >> b; int m = reverse_num(a); int n = reverse_num(b); sum = m + n; cout << reverse_num(sum); }
原文地址:http://blog.csdn.net/weijj6608/article/details/44788265