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

各位牛人,帮我看看我程序错在哪里,我的各个数据都对,怎么还是WA

Posted by 04105330 at 2008-04-05 10:58:16 on Problem 1001
#include<iostream>
#include<cstring>
#include<math.h>
using namespace std;

int pow1(int n,int m)
{
	int i, sum;
	sum = 1;
	for(i = 0;i <m;i++)
		sum = sum *n;
	return sum;
}
int main()
{
	char s1[10];
	int n,m1,m2,i,j,flg = 0,s;
	
	while(cin>>s1>>n)
	{
		m1 = 0;
		int a[300] = {0};
		m2 = strlen(s1);
		
		s = 0;
		for(i = 0,j = m2-1;j>=0;j--) //字符串小数整数
		{
			
			if(s1[j]!='.')
			{	if(s1[j] !='0'||i!=0)
			{
				s = s + pow1(10,i)*((int)s1[j] - 48);
				i++;}
			
			}
		}

		if(strchr(s1,'.')!=NULL) // 求小数点的位数
		{
			m1 = strchr(s1,'.') -s1;
			m1 = i -m1;
		}
		else
			m1 = 0;	

		a[0] = 1;  //求N次方
		for(i = 0; i< n;i++)
		{
			for(j = 0;j<300;j++)
				a[j] = a[j] * s;
			for( j = 0; j < 299;j++)
			{
				a[j+1] = a[j]/100+a[j+1];
				a[j] = a[j] %100;
			}
		}
		
		flg = 0; //输出整数部分
		int flg1 = 0;
		for(i = 299;i>=(m1*n)/2+1;i--)
		{
			if(a[i]!=0)
				flg = 1;
			if(flg ==1&&flg1==0){
				cout << a[i];
				flg1 = 1;
				flg = 2;
			}
			
			else if( flg1 == 1){
				if(a[i]>=10)
					cout << a[i];
				else
					cout << '0' << a[i];
			}
		}
		
		if((n*m1)%2==0) //输出小数点
		{
			if(a[i]!=0)
				flg = 1;
			if(flg ==1&&flg1==0){
				cout << a[i];
				flg1 = 1;
				flg = 2;
			}
			
			else if( flg1 == 1){
				if(a[i]>=10)
					cout << a[i];
				else
					cout << '0' << a[i];
			}
			if(i>0)
				cout << '.';
		}
		else
		{
			if(a[i]/10 != 0)
				cout << a[i]/10;
			cout <<'.';
			cout << a[i]%10;
		}
		


		i--; //输出小数部分
		for(;i>=0;i--){
			if(a[i]>=10)
				cout << a[i];
			else
				cout << '0'<< a[i];
			}
		
		cout << endl;
	}
	
	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