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:如何让小数点之前的0不显示出来呢

Posted by fantasyorg at 2007-12-29 21:55:50 on Problem 1001
In Reply To:如何让小数点之前的0不显示出来呢 Posted by:niedingding at 2007-12-21 10:04:36
> 如果是纯小数的情况,如何让小数点之前的0不显示出来呢
void print(int a[], int n, int p)
{
	int j, pp = 199 - (5 - p)*n;
	bool valid = true;
	 
	for (j = 199; j >= 0; j --)
	{
		if (j == pp)
		{	 
			valid = false;
			break;
		}
		if (a[j] != 0)
		{
			break;
		}
	}

	int k;
	for (k = 0; k < 200; k ++)
	{
		if (a[k] != 0)
			break;
		if (k == pp)
		{
			cout << '.';
			k ++;
			break;
		}	
	}

	for (int i = k; i <= j; i ++)
	{
		cout << a[i];
		if (i == pp && valid == true)
			cout << '.';
	}
	cout << endl;
}

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