RSS
![Table_bottom](/images/table_bottom.jpg?1375031774)
linjiazhen
![Avatar](/user_files/linjiazhen/config/avatar.png?1375032418)
![Table_bottom](/images/table_bottom.jpg?1375031774)
分类
![Table_bottom](/images/table_bottom.jpg?1375031774)
标签云
![Table_bottom](/images/table_bottom.jpg?1375031774)
搜索
![Table_bottom](/images/table_bottom.jpg?1375031774)
随机文章
![Table_bottom](/images/table_bottom.jpg?1375031774)
最新评论
![Table_bottom](/images/table_bottom.jpg?1375031774)
最新留言
![Table_bottom](/images/table_bottom.jpg?1375031774)
链接
![Table_bottom](/images/table_bottom.jpg?1375031774)
计数器
145657
![Table_bottom](/images/table_bottom.jpg?1375031774)
UVA 10018: Reverse and Add
Jasonlin
posted @ 2011年3月27日 15:40
in UVA
, 2637 阅读
题目大意:
一个数加上它反过来的数的和再做同样操作,直到这个和是一个回文数。
解题思路:
按照题目意思做,但是要注意数据大小,题目说是结果不大于4,294,967,295,所以用unsigned就行。
解题代码:
#include<iostream> using namespace std; unsigned reverse(unsigned n){ unsigned t=0; while(n){ t=t*10+n%10; n/=10; } return t; } int main(){ int n; cin>>n; while(n--){ unsigned t,c=0; cin>>t; while(t!=reverse(t)){ t+=reverse(t); c++; } cout<<c<<' '<<t<<endl; } }