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

明白了,else if(1<=p<=k-1)~

Posted by ybsb at 2006-01-22 23:31:36 on Problem 1032
In Reply To:小弟初学C,不知错在哪里~希望名位大哥大姐指教 Posted by:ybsb at 2006-01-22 23:00:09
> #include <stdio.h>
> int main()
> {
> 	int sum=0, k=2;
> 	int n;
> 	int i;
> 	int p;
> 	scanf("%d",&n);
> 	while(1)
> 	{
> 		for(i=2;i<=k;i++)
> 			sum+=i;
> 		if(sum<=n&&n<sum+k+1)
> 			break;
> 		sum=0;
> 		k++;
> 	}
> 	p=n-sum;
> 
> 	if(p==0)
> 		for(i=2;i<=k;i++)
> 			printf("%d ", i);
>     else if(1<=p<=k-1)
> 	{
> 		for(i=2;i<=k-p;i++)
> 			printf("%d ", i);
> 		for(i=k+2-p;i<=k+1;i++)
> 			printf("%d ", i);
> 	}
> 	else
> 	{
> 		for(i=3;i<=k;i++)
> 			printf("%d ", i);
> 		printf("%d ", k+2);
> 	}
> 	return 0;
> }

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