Hide That Number

点击打开链接

 

Hide That Number

Time Limit: 1000MS    Memory limit: 65536K

题目描述

According to Wikipedia, Cryptography is “the practice and study of hiding information” and this is exactly what Alex is looking for. Ever since he was a kid, Alex was paranoid over someone laying their hands on his phone book. He decided that he must write the numbers in some secret way that only he can decipher. At first he tried quite complex algorithms, but that slowed him down when he needed to dial a number fast. He finally came up with the following algorithm: Rather than writing down the number itself, Alex would shift the number one place to the left (as if multiplying it by 10,) then adding the shifted number to the original. For example, if the phone number was 123, Alex would add 1230 to it, resulting in 1353. To make what he writes looks as a regular phone number, Alex truncates the result (from the left,) so that it has as many digits as the original phone number. In this example, Alex writes 353 instead of 123 in his phone book.
Alex needs a program to print the original phone number given what is written in his phone book.  Alex, who by the way is a good friend of Johnny, isn’t that good in arithmetic. It is quite possible that the numbers are messed up. The program should print "IMPOSSIBLE" (without the quotes) if the original number cannot be computed.
 

输入

 Your program will be tested on one or more test cases. Each case is specified on a separate line and is made of a single positive number having less than 1, 000, 000 digits. The last line of the input file is made of a single zero.
 

输出

For each test case, output the result on a single line using the following format:
k._result
Where k is the test case number (starting at 1) and _ is a single space.
 
 

示例输入

353
9988
123456
0

示例输出

1. 123
2. IMPOSSIBLE
3. 738496

提示

 

来源

 

示例程序

 为什么把数组定义在main里面就错,然而定义在main外面就对了呢?
 
 
#include<stdio.h>
#include<string.h>
char m[1000007],z[1000007];
    int m1[1000007],z1[1000007];
int main()
{

    int count=1;
    while(scanf("%s",m)!=EOF)
    {
        if(strcmp(m,"0")==0)break;
        int len=strlen(m);
        int flag,flag1;
        z[0]=m[len-1];
        int b=1;
        for(int c=0;c<len;c++)
        {
            m1[c]=m[c]-'0';
        z1[c]=z[c]-'0';
        }

       for(int a=len-2;a>=0;a--)
       {
           if(m1[a]<z1[b-1])
           {z1[b++]=10+m1[a]-z1[b-1];m1[a-1]--;}
           else z1[b++]=m1[a]-z1[b-1];
       }
       printf("%d. ",count++);
       if(z1[len-1]==0)printf("IMPOSSIBLE\n");
       else{for(int b=len-1;b>=0;b--)
       printf("%d",z1[b]);
       printf("\n");
       }


    }
    return 0;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值