IO-04. Mixed type data format input (5) time limit MS Memory limit 65536 KB code length limit 8000 B procedure StandardAuthor Joleen (Tsinghua University)
The subject requires a program, sequentially read into the floating-point number 1, Integer, character, floating point number 2, and then by character, Integer, floating-point number 1, floating point number 2 order output.
Input format:
Enter the floating-point number 1, Integer, character, floating-point number 2 in the order given in a row, separated by 1 spaces.
Output format:
Output in a row in the order of characters, integers, floating-point number 1, floating-point number 2, where the floating-point number retains 2 digits after the decimal point.
Input Sample:
2.12 C 4.7
Sample output:
C 88 2.12 4.70
1#include <iostream>2#include <iomanip>3 using namespacestd;4 intMain ()5 {6 intA;7 floatb,c;8 CharD;9Cin>>b>>a>>d>>C;Tencout<<d<<" "<<a<<" " OneCout<<setiosflags (::fixed) <<setprecision (2) <<b<<" " ACout<<setiosflags (::fixed) <<setprecision (2) <<c<<Endl; - return 0; -}
Operation Result:
a.cpp:in function ' int main () ': a.cpp:11:4: error:expected '; ' Before ' cout '
Solution: A semicolon is added to each line after the cout.
1#include <iostream>2#include <iomanip>3 using namespacestd;4 intMain ()5 {6 intA;7 floatb,c;8 CharD;9Cin>>b>>a>>d>>C;Tencout<<d<<" "<<a<<" "; OneCout<<setiosflags (::fixed) <<setprecision (2) <<b<<" "; ACout<<setiosflags (::fixed) <<setprecision (2) <<c<<Endl; - return 0; -}
Run Result: Compile error
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) ' |
Solution: Leak the ios!!!! Ios::fixed
View Submission Evaluation Results
Time |
Results |
score |
Topics |
language |
spents (MS) |
memory (KB) |
User |
December 16 23:25 |
The answer is correct |
5 |
IO-04 |
C + + (g++ 4.7.2) |
1 |
368 |
Liyuhui |
Test point
Test Point |
Results |
spents (MS) |
memory (KB) |
Score/Perfect |
0 |
The answer is correct |
1 |
368 |
5/5 |
View Code
IO-04. Mixed type data format input (5)