AcWing 723. PUM
原题链接
简单
作者:
Backkom
,
2021-03-08 20:51:27
,
所有人可见
,
阅读 212
普通
#include <iostream>
using namespace std;
int main()
{
int n, m, x = 0;
cin >> n >> m;
for (int i = 1; i <= n; i ++)
{
for (int j = 1; j <= m; j ++)
{
x ++;
if (x % m == 0) cout << "PUM" <<endl;
else cout << x << ' ';
}
}
return 0;
}
第二种写法
#include <iostream>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
for (int i = 0, k = 1; i < n; i ++)
{
for (int j = 0; j < m -1; j ++)
{
cout << k << ' ';
k ++;
}
cout << "PUM" <<endl;
k ++;//k还要++
}
return 0;
}