Not done for a long timeAlgorithmQuestions, artificial algorithm questions, it is leisure and entertainment. The following is a simple question. I am not able to solve the problem. I can only start with a simple question.
Rounders
Time Limit: 1 second memory limit: 32768 KB
Introduction
For a given number, if greater than ten, round it to the nearest ten, then (if that result is greater than 100) Take the result and round it to the nearest hundred, then (if that result is greater than 1000) Take that number and round it to the nearest thousand, and so on...
Input
Input to this problem will begin with a line containing a single integer n indicating the number of Integers to round. the next n lines each contain a single integer x (0 <= x <= 99999999 ).
Output
For each integer in the input, display the rounded integer on its own line.
Note: Round Up On fives.
Sample Input
91514459912345678444444451445446
Sample output
20104510010000000500000002000500
In fact, this is a rounding question. I used to remember that the standard library had a rounding function, but now I haven't found it. It's really depressing. I 've been searching for it for a long time, in fact, it takes only a dozen seconds to write this simple algorithm. The question is relatively simple, that is, from 10 until the Division by the divisor is less than 1, the divisor is restored to the original value, and then return, the divisor starts from 10 to 10, 100, 1000, and 10000. Problem SolvingCodeAs follows:
1: # include <iostream>
2:
3: Using namespace STD;
4:/*
5: * rounding Functions
6 :*/
7:IntRound (DoubleD ){
8:Return(Int) (D + 0.5 );
9 :}
10:/*
11: * data processing functions
12 :*/
13:IntFormat (IntNum ){
14:If(Num <= 10 ){
15:ReturnNum;
16 :}
17:Else{
18:IntT = 10;
19:DoubleF = num * 1.0;
20:While(True){
21: F/= T;
22:If(F <1)ReturnF * = T;// If the value of F is less than 1, The devisor is restored and the result is returned.
23: F = round (f );
24: F * = T;
25: T * = 10;
26 :}
27 :}
28 :}
29:IntMain (){
30:IntN = 0;
31:While(CIN> N ){
32:IntIn;
33:While(N -- & CIN> in ){
34: cout <format (in) <Endl;
35 :}
36 :}
37:Return0;
38 :}
39: