poj3580
来源:互联网 发布:人事管理系统数据库 编辑:程序博客网 时间:2024/05/22 17:01
Home Page
F.A.Qs
Statistical ChartsCurrent Contest
Past Contests
Scheduled Contests
Award Contest1207020203 Log Out
Mail:0(0)
Login Log Archive
Description
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.
Input
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.
Output
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).
Sample Input
35399881234560
Sample Output
1. 1232. IMPOSSIBLE3. 738496
#include<stdio.h>#include<string.h>#include<malloc.h>char a[1000010],*b;main(){long i,j,k,z,count=1,flag=0;//freopen("D:\\p.txt","r",stdin);while(scanf("%s",&a)&&strcmp(a,"0")!=0){b=(char *)malloc(strlen(a)+1);b[strlen(a)]='\0';j=strlen(a)-1;k=0;memset(b,0,sizeof(b));b[j]=a[strlen(a)-1];for(i=strlen(a)-2;i>=0;i--,j--){if(k) {a[i]=a[i]-1;k=0;}if(a[i]-b[j]<0) {a[i]=a[i]+10;flag=1;}b[j-1]=a[i]-b[j]+'0';if(flag) {k=1;flag=0;}}if(b[j]!='0'){printf("%d. %s\n",count,b);}else printf("%d. IMPOSSIBLE\n",count);count++;}return 0;}
- poj3580
- POJ3580
- poj3580 SuperMemo
- SuperMemo POJ3580
- POJ3580 SuperMemo
- poj3580 splay
- POJ3580 splay
- poj3580 SuperMemo
- POJ3580 SuperMemo
- 【poj3580】 SuperMemo
- 【poj3580】【splay】SuperMemo
- poj3580 SuperMemo (splay)
- bzoj 1895||poj3580
- POJ3580 SuperMemo (Splay)
- POJ3580 SuperMemo(Splay)
- 【序列之神splay】poj3580
- poj3580 SuperMemo 伸展树 splay
- POJ3580 SuperMemo(区间树)
- 远距离CAN通讯终端电阻策略
- 应怎样提高外链的质量度?
- plsql回顾(3、debug存储过程或函数 ,函数基本)
- 主页权重合理分配
- 磁盘坏道的检测及修复
- poj3580
- javaScript中window对象的方法和属性
- libxml库解析XML文件
- P2P/WSN信任建模与仿真平台
- 作为一个新人,怎样学习嵌入式Linux?(韦东山)
- 实践五个步调对长尾词
- POJ 1324 Holedox Moving 搜索
- Keil4出现contains an incorrect path的提示
- Eclipse项目GBK编码转换