1 条题解
-
0
【本题解由站长编写】
输出是固定的 ASCII 排版,逐字节对齐即可:先打印标题行
Nine-by-nine Multiplication Table,一条 38 个-;然后是列标题行1..9(每个数右对齐在 4 宽度、整行前缩进 2 空格);再一条 38 个-;接着 9 行数据,每行先写行号(左对齐占 2 宽,如1),再依次把 1×i、i×… 的乘积右对齐在 4 宽度;最后再一条 38 个-。注意乘积不写乘号(是1 1而不是1*1=1),这点和常见的九九乘法表写法不同。代码(C++17)
#include <bits/stdc++.h> #include <iomanip> using namespace std; int main() { const string bar(38, '-'); cout << " Nine-by-nine Multiplication Table" << endl; cout << bar << endl; cout << " "; for (int j = 1; j <= 9; j++) cout << setw(4) << j; cout << endl; cout << bar << endl; for (int i = 1; i <= 9; i++) { cout << setw(2) << i; for (int j = 1; j <= i; j++) cout << setw(4) << j * i; cout << endl; } cout << bar << endl; return 0; }
- 1
信息
- ID
- 4226
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 6
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者