AcWing 723. PUM
原题链接
简单
作者:
启明_9
,
2024-04-24 20:27:58
,
所有人可见
,
阅读 4
PUM单层for循环求解
#include <iostream>
using namespace std;
int main()
{
int n ,m;
cin >> n >> m;
int k = n * m;
for(int i = 1; i <= k; i++){
if(i % m != 0){ //PUM再第M列上所以一定是M的倍数当i是M的倍数是则输出PUM加换行否则输出数字
cout << i << ' ';
}else{
cout << "PUM" << endl;
}
}
return 0;
}
PUM双层for循环求解
#include <iostream>
using namespace std;
int main()
{
int n, m, k = 1;
cin >> n >> m;
for(int i = 1; i <= n; i++){
for(int j = 1; j < m; j++){
cout << k << ' ';
k++;
}
cout << "PUM" << endl;
k++;
}
return 0;
}