본문 바로가기

Language Proficiency/C++

Print Pretty

Your manager gave you a text file with many lines of numbers to format and print. For each row of  space-separated doubles, format and print the numbers using the specifications in the Output Format section below.

Input Format

The first line contains an integer, , the number of test cases. 
Each of the  subsequent lines describes a test case as  space-separated floating-point numbers: , and , respectively.

Constraints

  • Each number will fit into a double.

Output Format

For each test case, print  lines containing the formatted , and , respectively. Each , and  must be formatted as follows:

  1. : Strip its decimal (i.e., truncate it) and print its hexadecimal representation (including the  prefix) in lower case letters.
  2. : Print it to a scale of  decimal places, preceded by a  or  sign (indicating if it's positive or negative), right justified, and left-padded with underscores so that the printed result is exactly  characters wide.
  3. : Print it to a scale of exactly nine decimal places, expressed in scientific notation using upper case.

Sample Input

1  
100.345 2006.008 2331.41592653498

Sample Output

0x64             
_______+2006.01  
2.331415927E+03

Explanation

For the first line of output,  (in reverse, ). 
The second and third lines of output are formatted as described in the Output Format section.




C++에서 숫자에 대한 자리수 포맷을 이용하는 문제이다.

이 문제를 풀기 위해서는 std::fixed, std::setw, std::setfill, std::hex, std::dec, std::scientific, std::setprecision 등, 포맷과 관련된 함수들을 잘 알고 있어야 한다.




'Language Proficiency > C++' 카테고리의 다른 글

Operator Overloading  (0) 2018.07.31
Deque-STL  (0) 2018.07.31
Maps-STL  (0) 2018.07.31
Variable Sized Arrays  (0) 2018.07.31
간단한 String 변수 다루기(Trim, 중복제거 등)  (0) 2018.07.27