【知识点】
整数 d → 字符 'd' 的转换代码为:d+'0'
【算法代码:多位整数】
#include <bits/stdc++.h>
using namespace std;
const int maxn=12;
char t[maxn],s[maxn];
int i,j;
int main() {
int x;
cin>>x;
while(x) {
t[i]=x%10+'0'; //int to char using +'0'
i++;
x=x/10;
}
cout<<t<<endl;
i-=1;
while(i>=0) {
s[j]=t[i]; //core code
j++;
i--;
}
cout<<s<<endl;
return 0;
}
/*
in:
678
out:
876
678
*/
【算法代码:一位整数】
#include <bits/stdc++.h>
using namespace std;
int main() {
int x;
cin>>x;
char t=x+'0'; //int to char using +'0'
cout<<t<<endl;
return 0;
}
/*
in:
7
out:
7
*/