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 00430030 at 2004-12-27 19:06:57 on Problem 2081
#include <stdio.h>
#include <math.h>
int f(int k)
{
	int i,a[1000];
    if(k==0)  a[k]=0;
	else
	for(i=1;i<=k;i++)
{   if(a[i-1]>=i)  a[i]=a[i-1]-i;
	else  a[i]=a[i-1]+i;
}
	return a[k];
}
void main ()
{
	int a;
    for(;;)
{
    scanf("%d",&a);
	if(a==-1)  break;
	printf("%d\n",f(a));
}
}

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