Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:如何让小数点之前的0不显示出来呢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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator