POJ Round and Round We Go 大数位乘法

题目的意思比较好理解:给一个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 + 5
int 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值