hackerrank>Dashboard>C++>STL>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.


第一个数以整形输出16进制,第二个数保留15个字符长·保留符号·保留两位小数·不足长补充'_',第三个数保留九位小数以科学计数法输出。。


恶补了一个函数库。。。。。


#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<<resetiosflags(ios::uppercase)<<setw(-0xf)<<"0x"<<hex<<(long long)A<<endl;
        cout<<setiosflags(ios::left)<<setiosflags(ios::showpos)<<setiosflags(ios::fixed)<<setw(15)<<setfill('_')<<setprecision(2)<<B<<endl;
        cout<<resetiosflags(ios::showpos)<<resetiosflags(ios::fixed)<<resetiosflags(ios::left);
        cout<< setiosflags(ios::uppercase)<<setiosflags(ios::scientific)<<setprecision(9)<<C<<endl;
        cout<<resetiosflags(ios::uppercase)<<resetiosflags(ios::scientific);//此处之后无法改动
	}
	return 0;

}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值