码迷,mamicode.com
首页 > 其他好文 > 详细

IO-04. 混合类型数据格式化输入(5)

时间:2014-12-17 00:16:39      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   ar   io   color   os   sp   for   

IO-04. 混合类型数据格式化输入(5)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
乔林(清华大学)

本题要求编写程序,顺序读入浮点数1、整数、字符、浮点数2,再按照字符、整数、浮点数1、浮点数2的顺序输出。

输入格式:

输入在一行中顺序给出浮点数1、整数、字符、浮点数2,其间以1个空格分隔。

输出格式:

在一行中按照字符、整数、浮点数1、浮点数2的顺序输出,其中浮点数保留小数点后2位。

输入样例:
2.12 88 c 4.7
输出样例:
c 88 2.12 4.70
 1 #include <iostream>
 2 #include <iomanip>
 3 using namespace std;
 4 int main()
 5 {
 6    int a;
 7    float b,c;
 8    char d;
 9    cin>>b>>a>>d>>c;
10    cout<<d<<" "<<a<<" "
11    cout<<setiosflags(::fixed)<<setprecision(2)<<b<<" "
12    cout<<setiosflags(::fixed)<<setprecision(2)<<c<<endl;
13    return 0;
14 }

运行结果:

a.cpp: In function ‘int main()‘:
a.cpp:11:4: error: expected ‘;‘ before ‘cout‘
解决方案:在每一行的cout后都加了分号。
 1 #include <iostream>
 2 #include <iomanip>
 3 using namespace std;
 4 int main()
 5 {
 6    int a;
 7    float b,c;
 8    char d;
 9    cin>>b>>a>>d>>c;
10    cout<<d<<" "<<a<<" ";
11    cout<<setiosflags(::fixed)<<setprecision(2)<<b<<" ";
12    cout<<setiosflags(::fixed)<<setprecision(2)<<c<<endl;
13    return 0;
14 }

运行结果:编译错误

a.cpp: In function ‘int main()‘:
a.cpp:11:29: error: cannot convert ‘std::ios_base& (*)(std::ios_base&)‘ to ‘std::ios_base::fmtflags {aka std::_Ios_Fmtflags}‘ for argument ‘1‘ to ‘std::_Setiosflags std::setiosflags(std::ios_base::fmtflags)‘
a.cpp:12:29: error: cannot convert ‘std::ios_base& (*)(std::ios_base&)‘ to ‘std::ios_base::fmtflags {aka std::_Ios_Fmtflags}‘ for argument ‘1‘ to ‘std::_Setiosflags std::setiosflags(std::ios_base::fmtflags)‘

解决方案:漏了ios!!!!ios::fixed

查看提交

评测结果

时间结果得分题目语言用时(ms)内存(kB)用户
12月16日 23:25 答案正确 5 IO-04 C++ (g++ 4.7.2) 1 368 liyuhui

测试点

测试点结果用时(ms)内存(kB)得分/满分
0 答案正确 1 368 5/5

查看代码

IO-04. 混合类型数据格式化输入(5)

标签:style   blog   http   ar   io   color   os   sp   for   

原文地址:http://www.cnblogs.com/liyuhui20093357/p/4168372.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!