6-6 你好,輸出的格式控制(對齊)
分數 10
全屏瀏覽
切換布局
作者?向訓文
單位?惠州學院
完善程序:按示例格式輸出所有分數,分數保留2位小數,分數左對齊輸出在兩根豎線之間
裁判測試程序樣例:
#include <iostream> #include <string> #include <iomanip> using namespace std; int main() { const int N = 3; double scores1[N], scores2[N], scores3[N]; for (int i = 0; i < 3; ++i) { cin >> scores1[i] >> scores2[i] >> scores3[i]; // 每個分數>0且<=100 } // 請將答案填寫在這里 return 0; }
輸入樣例:
在這里給出一組輸入。例如:
98.5 98 97.2
88 92.5 99.55
98 65 62.5
輸出樣例:
在這里給出相應的輸出。例如:
|score1|score2|score3|
|98.50 |98.00 |97.20 |
|88.00 |92.50 |99.55 |
|98.00 |65.00 |62.50 |
代碼長度限制
16 KB
時間限制
400 ms
內存限制
64 MB
cout.precision(2);
cout.setf(ios::fixed);
cout<<"|score1|score2|score3|"<<endl;
for(int i=0;i<3;i++){cout<<setiosflags(ios::left)<<'|'<<setw(5)<<setfill(' ')<<scores1[i]<<" |"<<setw(5)<<setfill(' ')<<scores2[i]<<" |"<<setw(5)<<setfill(' ')<<scores3[i]<<" |"<<endl;
}