POJ 1047 Round and Round We GO
来源:互联网 发布:上海万达网络科技集团 编辑:程序博客网 时间:2024/05/16 02:40
题目链接 :POJ 1047 Round and Round We Go
数学题。。判断一个数字(可以多达60位)是否是循环数,循环数的定义给出了。
从数论的角度可以推出 :如果一个n位整数num ,num*(m+1)为n个9,那么这个数是可循环的
做到这道题的时候还没学过数论,这个结论是搜题解搜到的。。。期待暑期集训能系统的学习数论吧。。
要点:因为数字可以很长,基本的int 和long long肯定是不够的,这里用的字符串处理方法是用STL里面的<string>类。
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>#include <string>//就是它using namespace std;string num;bool check;int len;int main(){while(cin>>num){check=true;len=num.size()+1;//size是string的一个成员函数。返回字串长度,这个确实比传统的 char数组方便些,更多功能还需要探索int tmp=0;int dig=0;for(int i=len-2; i>=0;i--){dig=num[i]-'0';if((dig*len+tmp) % 10 !=9)//每一位的处理,取乘上len(即所谓的 n+1)取10的余数{check = false;break;}tmp=(dig*len + tmp)/10;//快速求余的方法。。}if(check){cout<<num<<" is cyclic"<<endl;}else{cout<<num<<" is not cyclic"<<endl;}}}
0 0
- Round and Round We Go POJ 1047
- poj 1047 Round and Round We Go
- poj 1047 Round and Round We Go
- POJ 1047 Round and Round We Go
- POJ 1047 Round and Round We Go
- poj 1047 Round and Round We Go
- POJ 1047 Round and Round We Go
- poj 1047-Round and Round We Go
- POJ 1047 Round and Round We GO
- poj 1047 Round And Round We Go
- POJ 1047 Round and Round We Go
- POJ 1047 Round and Round We Go 循环数新解
- poj 1047 Round and Round We Go 字符串的处理
- POJ 1047 Round and Round We Go (大数乘法) 水
- POJ 1047 Round and Round We Go 已被翻译
- Round and Round We Go
- Round and Round we go
- Round and Round We Go
- hadoop系列端口
- Javascript闭包
- 自启动项与清单读取,简单的拨号软件
- TreeMap和TreeSet
- 第一天博客
- POJ 1047 Round and Round We GO
- 基于GPU的CUDA
- 浏览器兼容之CSS Hack
- 【Android 新浪微博】--底部Tab的实现
- 异常处理
- android 系统广播
- C/C++ 位移与乘除法的换算
- 求助!itk读取保存图像问题!
- jquery 选择器(name,属性,元素)大全