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 |
这题用字符串做超级简单,附代码供参考int main(){ char s[16],*p,*q,a,b; int t; scanf("%d", &t); while (t--){ //数组s[0]留给进位用的,所以从s[1]接受输入 s[0] = 0; scanf("%s", s + 1); p = s + 1; // 非1位数字才需要处理 if (p[1]) { // 移动到字符串结尾 while (*p++); p -= 2; q = p - 1; // 从后往前遍历,4舍5入后相应位改为'0' while (1){ b = *q; a = *p; if (0 == b){ if (a - '0' > 9){ *p = a - 10; p = s; *p = '1'; } else p = s + 1; break; } *p = '0'; if (a > '4')*q = b + 1; p--; q--; } } printf("%s\n", p); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator