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

Re:为什么是runtime error?

Posted by forsona at 2009-03-01 22:13:24 on Problem 1929
In Reply To:为什么是runtime error? Posted by:kobe8936 at 2008-11-20 23:47:33
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
using namespace std;
char input[100000][1000];   //-------------------------------->把数组开大,而且变成全局的变量
int pround(float f)
{
	float eps=0.49;
	int i=(int)f;
	if((f-(float)i)<eps)
		return i;
	else 
		return i+1;
}

int main()
{
	float sumall=0,fat=0;
	int i=0,percent=0;float sum=0;
    bool end=false;
	while (1)
	{
		int temp,len;
        scanf("%s",input[i]);
		if (strcmp(input[i],"-")==0&&end==true)
		     break;
		end=false;
		if (strcmp(input[i],"-")==0)
		{
			float per=fat*100/sumall;
			printf("%d",pround(per));
			printf("%%\n");
			sumall=0;fat=0;
			end=true;
			continue;
		}
		len=strlen(input[i]);
		sscanf(input[i],"%d",&temp);		
		if (input[i][len-1]=='C') //------------->把原来的c改成C
		{
			sum+=temp;
			if (i%5==0)
			{
               fat+=temp;
			}
		}
		else if (input[i][len-1]=='g')
		{
			if (i%5==0)
			{
				sum+=temp*9;
				fat+=temp*9;
			}
			else if (i%5==4)
			{
				sum+=temp*7;
			}
			else
			{
				sum+=temp*4;
			}
		}
		else if (input[i][len-1]=='%')
		{
			if (temp>100)
			   break;
			percent+=temp;
		}
		if (i%5==4)
		{
			if (percent!=0)
			{
				sum=sum*100/(float)(100-percent);
				len=strlen(input[i-4]);
				if(input[i-4][len-1]=='%')
				{
					sscanf(input[i-4],"%d",&temp);
					fat+=temp*sum/100.0;
				}
			}
			sumall+=sum;
			sum=0;percent=0;
		}
		i++;
	}
}

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