Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这题用字符串做超级简单,附代码供参考

Posted by Eov_Second at 2016-12-02 13:31:23 on Problem 3077
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator