Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
给个代码,给不过的一个参考(有注释)#include<stdio.h> #include<string> int main() { int index=0; while(1) { char str[1000000]; scanf("%s",&str); ++index; if( !strcmp(str,"0") ) break; char last = str[strlen(str) - 1]; int flg = 0;//向高位借位 for (int j = strlen(str) - 2; j >= 0; j--) { int tt = str[j] - last; if (flg + tt < 0) //产生借位:加10,借位 { str[j] = (char) ('0' + flg + tt + 10); flg = -1; } else { str[j] = (char) ('0' + flg + tt); flg = 0; } last = str[j]; } if (str[0] != '0') //首位为0,位数不同,IMPOSSIBLE printf("%d. %s\n",index,str); else printf("%d. IMPOSSIBLE\n",index); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator