Recent Post

Print Pretty.cpp-HackerRank

Problem-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.

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.

Solution-

#include <iostream>
#include <iomanip> 
using namespace std;

int main() {
    int T; cin >> T;
    cout << setiosflags(ios::uppercase);
    cout << setw(0xf) << internal;
    while(T--) {
        double A; cin >> A;
        double B; cin >> B;
        double C; cin >> C;
        cout << hex << showbase << nouppercase<<left;
        cout << (long long)A << endl;
        cout << setw(15) << showpos << setfill('_') << setprecision(2)<<fixed<<right;
        cout << B << endl;
        cout << scientific << setw(15) << setprecision(9) << uppercase<<noshowpos;
        cout << C << endl;
    }
    return 0;
}


Link to the problem-

Result!

Comments

Popular posts from this blog

Caesar Cipher.c-HackerRank

Bon Appétit.c-HackerRank

Electronics Shop.c-HackerRank