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 15889938871 at 2011-04-07 16:31:45 on Problem 3979
#include<iostream>
using namespace std;
class fraction
{
public:
	void judge1( int m ) { if(m<0||m>9) {cout << " error!" << endl; exit(0);}}
	void judge2(int m, int n, int j, int k,char a);
	void getresulte(int m, int n, int j, int k);
	int gcd( int n, int m);
	void print();
private:
	int a, b;
	bool x;
};

void fraction :: judge2(int m, int n, int j, int k,char a)
{
	judge1(n);
	judge1(m);
	judge1(j);
	judge1(k);
	switch (a)
	{
	case '+': { x = 1; break;}
	case '-': { x = 0; break;}
	default:  { exit(0); }
	}
}



int fraction::gcd( int n,int m)
{
	int r = n%m;
	if(!r)
		return m;
	else
		return gcd (m,r);
}

void fraction :: getresulte( int n, int m, int j, int k)
{
	if (x)
		a = n*k + m*j;
	else
		a = n*k - m*j;
	b = m*k;
        int temp;
	temp = gcd (abs(a), b);
	a = a/temp;
	b = b/temp;
}

void fraction :: print()
{
	if (a==0)
		cout  << "0" << endl;
	else
		if(b == 1)
			cout << a <<endl;
		else
			cout << a << "/" << b <<endl;
}

int main()
{
	fraction A[100];
	char *s;
	s = new char[8];
	int i;
	cin >>s;
	int a = atof(&s[0]);
	int b = atof(&s[2]);
	int c = atof(&s[4]);
	int d = atof(&s[6]);
	A[0].judge2 (a,b, c, d, s[3]);
	A[0].getresulte (a, b, c, d);
	for( i =1; i<100;i++)
	{
		cin >>s;
		if (strcmp(s,"EOF")==0)
			break;
		a = atof(&s[0]);
		b = atof(&s[2]);
		c = atof(&s[4]);
		d = atof(&s[6]);
		A[i].judge2 (a,b, c, d, s[3]);
		A[i].getresulte (a, b, c, d);
	}

	for(int j=0;j<i;j++)
	{
		A[j].print ();
	}
}









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