POJ 3508 Hide That Number

思路:

题意是将得到的数从左边开始删去位数,直到与最开始的数位数一样。
1)设原来的数是x,那么x*10 + x = 11x 所以通过枚举1-10来判断这个大数是否可以模开11。注意是枚举1到10,因为有可能出现进位导致的删去了两位。
2)如图
这里写图片描述
最后只要判断首位能否为0就行了。

模拟大数取模

#include <iostream>
#include <cstdio>
#include <string.h>
#include <queue>
#include <algorithm>
typedef long long int lli;
using namespace std;


char s[10001000];
char ans[10001000];
int len;
int cnt;

bool ju(){
    for(int i = 1;i <= 10;i++){
        cnt = 0;
        int temp = i;
        for(int j = 0;j < len;j++){
            ans[cnt++] = ( temp*10 + s[j] - '0' ) / 11 + '0';
            temp  = ( temp*10 + s[j] - '0' ) % 11;
        }
        if(temp == 0){
            ans[cnt] = '\0';
            return true;
        }
    }
    return false;
}

int main(){
    int tcase = 0;
    while(scanf("%s",s)){
        len = strlen(s);
        if(len == 1 && s[0] == '0')
            break;
        tcase++;
        if(ju()){

            printf("%d. %s\n",tcase,ans);
        }
        else{
            printf("%d. IMPOSSIBLE\n",tcase);
        }
    }
}

错位相减

#include <iostream>
#include <cstdio>
#include <string.h>
#include <queue>
#include <algorithm>
typedef long long int lli;
using namespace std;


char s[10001000];
char ans[10001000];
int len;
int cnt;

bool ju(){
    for(int i = 1;i <= 10;i++){
        cnt = 0;
        int temp = i;
        for(int j = 0;j < len;j++){
            ans[cnt++] = ( temp*10 + s[j] - '0' ) / 11 + '0';
            temp  = ( temp*10 + s[j] - '0' ) % 11;
        }
        if(temp == 0){
            ans[cnt] = '\0';
            return true;
        }
    }
    return false;
}

int main(){
    int tcase = 0;
    while(scanf("%s",s)){
        len = strlen(s);
        if(len == 1 && s[0] == '0')
            break;
        tcase++;
        if(ju()){

            printf("%d. %s\n",tcase,ans);
        }
        else{
            printf("%d. IMPOSSIBLE\n",tcase);
        }
    }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值