hdu 6297(常用的输出格式总结)
题目链接:https://cn.vjudge.net/problem/HDU-6297
题目介绍:一道关于输出格式规范问题
wrong answer代码:
#include<iostream>
#include<cstdio>
#include<string.h>
#include<string>
using namespace std;
int main()
{
int T;
cin>>T;
int rank;
string str;
int prob;
string Tstr;
while(T--)
{
int n=;
cin>>rank>>str>>prob>>Tstr;
if(Tstr[]=='R')
cin>>n;
printf("%3d|",rank);
int mylen=str.length();
cout<<str;
for(int i=mylen;i<=;i++)
cout<<" ";
printf("|%d|[",prob);
if(Tstr[]=='R')
{
for(int i=;i<=n;i++)
cout<<"X";
for(int i=n;i<=;i++)
cout<<" ";
cout<<"]"<<endl;
}
else
{
int length=Tstr.length();
for(int i=;i<=;i++)
cout<<" ";
if(Tstr[]=='F'&&Tstr[]=='B')
{
length=;
cout<<"AC*";
}
else
cout<<Tstr;
for(int i=length+;i<=;i++)
cout<<" ";
cout<<"]"<<endl; }
}
return ;
}
错误点:
1.识别Tstr字符串是否为“Running"时,只以首字母标记(Tstr[0]=='R'),导致识别资料不足,可以识别“RTE"与”Running",识别混乱,所以改成(Tstr==”Running")
2.与输出样式相比,末尾多输出了一个空格
ac代码:
#include<iostream>
#include<cstdio>
#include<string.h>
#include<string>
using namespace std;
int main()
{
int T;
cin>>T;
int rank;
string str;
int prob;
string Tstr;
while(T--)
{
int n=;
cin>>rank>>str>>prob>>Tstr;
if(Tstr=="Running")
cin>>n;
printf("%3d|",rank);
int mylen=str.length();
cout<<str;
for(int i=mylen;i<=;i++)
cout<<" ";
printf("|%d|[",prob);
if(Tstr=="Running")
{
for(int i=;i<=n;i++)
cout<<"X";
for(int i=n;i<;i++)
cout<<" ";
cout<<"]"<<endl;
}
else
{
int length=Tstr.length();
for(int i=;i<=;i++)
cout<<" ";
if(Tstr[]=='F'&&Tstr[]=='B')
{
length=;
cout<<"AC*";
}
else
cout<<Tstr;
for(int i=length+;i<;i++)
cout<<" ";
cout<<"]"<<endl;
}
}
return ;
}
接下来,我们来学习一下常用的输出格式:
头文件:#include<iomanip>
以下是一些常用的: dec 置基数为10 相当于"%d"
hex 置基数为16 相当于"%X"
oct 置基数为8 相当于"%o"
setfill(c) 设填充字符为c
setprecision(n) 设显示小数精度为n位
setw(n) 设域宽为n个字符
setioflags(ios::fixed) 固定的浮点显示
setioflags(ios::scientific) 指数表示
setiosflags(ios::left) 左对齐
setiosflags(ios::right) 右对齐
setiosflags(ios::skipws 忽略前导空白
setiosflags(ios::uppercase) 16进制数大写输出
setiosflags(ios::lowercase) 16进制小写输出
setiosflags(ios::showpoint) 强制显示小数点
setiosflags(ios::showpos) 强制显示符号
代码举例:
19|qqqqq_University|1001|[XXX ]
125|quailty_U_2 |1002|[ WA ]
4|quailty_U_3 |1003|[ TLE ]
比如上面的那道题,需要用到输出时每个数据是 右对齐3 左对齐16 4 10
像第一个数据需要右对齐:cout<<right<<setw(3)<<Rank<<"|";
第二个数据需要左对齐:cout<<left<<setw(16)<<name<<"|";
第三个数据左对齐:cout<<left<<setw(4)<<pro<<"|[";
第四个需要分类:
针对下面两个的类型:输出字符串,但字符串是居中的(我们可以这样处理:先输出四个空字符,然后对字符串进行左对齐:cout<<" "<<setw(6)<<status<<"]"<<endl;
hdu 6297(常用的输出格式总结)的更多相关文章
- Hadoop MapReduce常用输入输出格式
这里介绍MapReduce常用的几种输入输出格式. 三种常用的输入格式:TextInputFormat , SequenceFileInputFormat , KeyValueInputFormat ...
- Hadoop学习之常用输入输出格式总结
目的 总结一下常用的输入输出格式. 输入格式 Hadoop可以处理很多不同种类的输入格式,从一般的文本文件到数据库. 开局一张UML类图,涵盖常用InputFormat类的继承关系与各自的重要方法(已 ...
- geoserver 数据图层输出格式
1.WMS服务请求参数 一般WMS的请求地址如下: http://localhost:8080/geoserver/topp/wms?service=WMS&versi on=1.1.0&am ...
- Log4net快速索引参考
官方项目地址:The Apache log4net project 本文内容仅为相关项参考,不进行具体使用讨论 另转载请注明出处 Log4net快速索引参考 Log4net主要有以下三个部件: log ...
- java 日期格式化
DateFormat DateFormat 是日期/时间格式化子类的抽象类,它以与语言无关的方式格式化并解析日期或时间. SimpleDateFormat SimpleDateFormat 是一个以与 ...
- 细说log4j之log4j 1.x
官网:http://logging.apache.org/log4j/1.2/manual.html 三大组件:loggers,appenders,layouts. LoggersLogger是一个层 ...
- Verilog中的$display和$write任务
$display(p1,p2, …,pn); $write(p1,p2, …,pn); 这两个函数和系统任务的作用都是用来输出信息,即将参数p2到pn按参数p1给定的格式输出.参数p1通常称为:“格式 ...
- Verilog的一些系统任务(一)
$display.$write;$fopen.$fdisplay.$fclose;$strobe $display和$write任务 格式: $display(p1,p2,...pn); $w ...
- Log4j日志框架小记
人啊,总是在学习中发现不足,不足中学习,学习中成长. 今天来系统记录一下对于常用日志组件的理解.配置.使用. 仅供参考, 错误之处请各路好汉不吝笔墨批评指正. 转载请注明出处 Log4j日志框架是Ap ...
随机推荐
- Realsense深度相机资料
1.Realsense SDK 2.0 Ubuntu 16.04 安装指导网址 https://github.com/IntelRealSense/librealsense/blob/master/d ...
- php学习笔记-php中的比较运算符
其中比较难懂的是==和=== ==是只比较两个变量的值,不仅仅是用于比较两个数是否相等,还可以比较int和string,不过会先转化string为int类型再比较,值相等则返回true,值不相等则返回 ...
- Entity Framework Code-First(21):Automated Migration
Automated Migration: Entity framework 4.3 has introduced Automated Migration so that you don't have ...
- SDUT 3403 数据结构实验之排序六:希尔排序
数据结构实验之排序六:希尔排序 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 我们已经学习 ...
- 【Arcgis for android】保存地图截图到sd卡
关键词:arcgis for android ,截图,bitmap,sd卡 参考文章:http://blog.csdn.net/wozaifeiyang0/article/details/767972 ...
- mongodb对数组中的元素进行查询详解
原文链接:http://blog.csdn.net/renfufei/article/details/78320176 MongoDB中根据数组子元素进行匹配,有两种方式. 使用 “[数组名].[子元 ...
- vmware vmware esxi5.x安装方法及解决错误
vmware Esxi5.x安装指南 vmware Esxi5文档中心官网地址: http://pubs.vmware.com/vsphere-55/index.jsp?topic=%2Fcom.vm ...
- docker常用命令行集锦
对工作中用到的docker命令行进行一个汇总,方便以后的命令行查询,同时也为了加强记忆,会把工作中用到的命令,持续更新上 1.查看私有仓库都有哪些镜像 curl -X GET http://10.27 ...
- Android - AndroidStudio 的熟悉
开发环境 * JDK * SDK * AndroidStudio * Genimotioin HelloWorld [ 第一个Android项目建立 ] * 创建项目 [ 项目相关目录 ] Hell ...
- PL/0语言词法分析器
前言:关于词法分析的基础知识的介绍可以看一下这篇博客,我再累述估计也不会有这篇讲的清楚QAQ. https://www.cnblogs.com/yanlingyin/archive/2012/04/1 ...