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:求助:1001 runtime error(附程序)

Posted by bgeng at 2007-05-21 15:28:28
In Reply To:求助:1001 runtime error(附程序) Posted by:bgeng at 2007-05-21 14:26:02
问题已解决,考虑情况不够全面。


> 在我的机器上跑一点问题没有
> 
> 提交就显示,真的看不出是什么原因
> 
> 各位帮忙,先谢过了~~
> 
> #include <iostream>
> #include <cmath>
> #include <vector>
> #include <string>
> #include <cstdio>
> 
> using namespace std;
> 
> int preprocess(string str ,int * exp1)
> {//pre process the input string
> 
> 	if(str[0]<0x30||str[0]>0x39)return 0;
> 	int j=0;
> 	int i=0;
> 	for(;i<6;i++)
> 	{
> 		if(str[i]=='.')
> 			exp1[5]=i;	//point to the number after the decimal point
> 		else{
> 			exp1[j]=str[i]-0x30;
> 			j++;
> 		}
> 	}
> 
> /*	if(str[8]>=0x30||str[8]<=0x39)
> 		if(str[7]>=0x30&&str[7]<=0x39)
> 			n[index]=(str[7]-0x30)*10+(str[8]-0x30);
> 		else n[index]=str[8]-0x30;
> 	else
> 		return 0;
> */	
> //	for(i=0;i<6;i++)cout<<exp1[i];
> 	//cout<<n[index]<<endl;
> 	return 2;
> }
> void cal_mul(int * tmp, int * exp1, int & upside ,int & lowside);
> 
> void cal_exp(int * tmp, int * exp1,int n)
> {
> 	int j;
> 	for(j=0;j<200;j++)tmp[j]=0;	//clear the tmp array
> 	int dp=exp1[5];			//tmp[100] -> the number before the decimal point 
> 	for(j=0;j<5;j++)
> 		tmp[101-dp+j]=exp1[j];
> 
> 	int upside=101-dp;
> 	int lowside=105-dp;
> 
> 	for(j=0;j<n-1;j++)
> 		cal_mul(tmp,exp1,upside,lowside);
> 
> 	tmp[0]=upside;
> 	tmp[1]=lowside;
> 
> 	return ;
> }
> 
> void cal_mul(int * tmp, int * exp1, int & upside ,int & lowside)
> {
> 
> 	int dp=exp1[5];
> 	int i=0;
> 	int tmp1[200];
> 	for(;i<200;i++)tmp1[i]=0;
> 	int up_tmp,low_tmp;
> 	int carry=0,res_tmp,carry_tmp;
> 	int base;
> 
> 	low_tmp=lowside+(6-dp);
> 	for(i=lowside;i>=upside;i--)//calculate from right to left
> 	{
> 		for(int j=4;j>=0;j--)
> 		{
> 			base=i+(j-dp+1);
> 
> 			carry_tmp=(tmp[i]*exp1[j])/10;
> 			res_tmp=tmp[i]*exp1[j]-carry_tmp*10;
> 
> 			tmp1[base]+=carry;
> 			tmp1[base]+=res_tmp;
> 
> 			carry=tmp1[base]/10;
> 			tmp1[base]=tmp1[base]-carry*10;
> 			carry+=carry_tmp;
> 			
> 			if(j==0&&carry!=0)
> 			{
> 				tmp1[base-1]+=carry;
> 				up_tmp=base-1;
> 			}else
> 				up_tmp=base;
> 		}
> 
> 		carry=0;
> 	}
> 	for(i=0;i<200;i++)
> 	{
> 		tmp[i]=tmp1[i];
> 	}
> 	upside=up_tmp;
> 	lowside=low_tmp;
> 
> 	return ;
> }
> 
> void display(int * tmp)
> {
> 	int upside=tmp[0];
> 	int lowside=tmp[1];
> 	int i;
> 
> 	i=lowside;
> 	while(i>100&&tmp[i]==0)i--;
> 	lowside=i;
> 	if(upside<=100)
> 		if(!(upside==100&&tmp[100]==0))
> 		for(i=upside;i<=100;i++)
> 			cout<<tmp[i];
> 	if(lowside>100)
> 		cout<<'.';
> 	for(i=101;i<=lowside;i++)
> 		cout<<tmp[i];
> 
> 	cout<<endl;
> 
> 	return;
> }
> 
> void main()
> {
> 	vector<string> inums(100);
> 	char chartmp[10];
> 	int i=0,j=0;
> 	int cal_group;
> 	int exp[100][6];
> 	int n[100];
> 	int tmp[200];
> 	int icont=2;
> 
> 
> 	while(cin>>inums[i]>>n[i]){
> 
> 		icont=preprocess(inums[i],exp[i]);
> 		i++;
> 	}
> 	cal_group=i;
> 	i=0;
> 
> 	while(i<cal_group)
> 	{
> 
> 		cal_exp(tmp,exp[i],n[i]);
> 
> 		display(tmp);
> 
> 
> 		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