這樣反覆做就可以得到數字翻轉的結果。
[C++](4ms, 700KB)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
int main() | |
{ | |
int n; | |
while( cin >> n ) | |
{ | |
int n_rev = 0; | |
while( n ) | |
{ | |
n_rev *= 10; | |
n_rev += n % 10; | |
n /= 10; | |
} | |
cout << n_rev << endl; | |
} | |
return 0; | |
} |
0 意見:
張貼留言