Print Pretty

Sort by

recency

|

186 Discussions

|

  • + 0 comments

    Solution by C++14

    #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 << setw(0) << setiosflags(ios::showbase) << resetiosflags(ios::uppercase);
            cout << (long long)A << endl;
    
            cout << right << setfill('_') << setw(15) << setprecision(2) << fixed << setiosflags(ios::showpos);
            cout << B << endl;
    
            cout << resetiosflags(ios::showpos) << setiosflags(ios::uppercase) << setprecision(9) << scientific;
            cout << C << endl;
    
            
    	}
    	return 0;
    
    }
    
  • + 0 comments

    Here is Print Pretty problem solution in C++ - https://programmingoneonone.com/hackerrank-print-pretty-solution-in-cpp.html

  • + 0 comments

    simple is best

    cout << left << nouppercase << hex << showbase << (long long)A << endl;

        cout << setfill('_') << setw(15) << right << showpos << fixed << setprecision(2) << B << endl;
    
        cout << uppercase << noshowpos << scientific << setprecision(9) << C << endl;
    
  • + 0 comments

    IIt helped me, Thank you so much.

  • + 1 comment

    Sicne they have included iomanip

    #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;
    
    		/* Enter your code here */
            //find length of the B's realpart 
            long int temp = int(B);
            int digitCount=0;
            while(temp)
            {
                digitCount++;
                temp/=10;
            }
            //add 3 (. + 2decimal part)
            digitCount+=3;
            cout <<setw(0)<< showbase << hex <<nouppercase<< (long long) A<<endl;
            cout<<uppercase<<setw(0xf);
            cout << setw(15 - digitCount)<<setfill('_')<<'+'<<fixed<<setprecision(2)<<B<<endl;
            cout << scientific <<setprecision(9)<< C << endl;
            cout.precision();
            cout<< defaultfloat;
            
    	}
    	return 0;
    
    }