POJ Round and Round We Go 大数位乘法
来源:互联网 发布:林黛玉最后的结局 知乎 编辑:程序博客网 时间:2024/05/18 01:05
题目的意思比较好理解:给一个n位的数,让这个数乘1~n,得到的数每个位的数字能在给出的数的数位中找到一一对应的数位(位置可以不一样),那么这个数就满足题目要求
由于给的数最多60位,所以就需要大数的思想了,至于如何判断是不是一一对应,我们可以用一个数组count【i】来表示i出现的次数,在新得到数里面,i没出现一次,就count【i】--,如果count【i】为0,这个i还出现,说明不满足要求
#include<cstdio>#include<cstring>#include<iostream>using namespace std;#define MAXD 60 + 5int main(){ char Num[MAXD]; int count[10L],countx[10L]; while(scanf("%s",Num) != EOF){ memset(count,0,sizeof(count)); int L = strlen(Num); int ok = 1; for(int i = 0 ; i < L ; i ++) count[Num[i] - '0'] ++; if(L == 1) printf("%s is cyclic\n",Num); for(int k = 2 ; k <= L ; k++){ memcpy(countx,count,sizeof(countx)); int p,t,cnt = 0; for(int i = L - 1; i >= 0 ; i--){ t = cnt + (Num[i] - '0') * k; cnt = t / 10; p = t % 10; if(countx[p]) countx[p]--; else { ok = 0; break; } } while(t >= 10){ p = t % 10; if(countx[p]) countx[p]--; else { ok = 0; break; } t = t / 10; } } if(ok) printf("%s is cyclic\n",Num); else printf("%s is not cyclic\n",Num); } return 0;}
0 0
- POJ Round and Round We Go 大数位乘法
- POJ 1047 Round and Round We Go (大数乘法) 水
- hdu1313 Round and Round We Go (大数乘法)
- POJ 1047Round and Round We Go——大数乘法+匹配
- POJ 1049 Round and Round We Go 大数模拟
- POJ Round and Round We Go(核心大数相乘算法)
- 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
- ZOJ 1073 Round and Round We Go(高精度乘法)
- fuse的安装与使用
- matlab中sum函数求和
- fork创建子进程和父进程
- 为什么处理有序数组比无序数组快?
- 第7周作业1——背包问题
- POJ Round and Round We Go 大数位乘法
- NSAttributedString 详解
- 从无秘和知乎看中国社交产品的特点
- Android中的缩略图加载-不浪费一点多余的内存
- Leetcode: Integer to Roman
- android ota 升级包制作分析 (4 设计细节)
- 两个kmp hdu 2594 & hdu 2087
- 关于Activity的生命周期及其作用
- Matlab function如何使用全局变量