PTA L1-7 矩阵列平移

#include<bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N][N];
int n, k, x;
void solve() {
	int t = 0;
	/*for (int i = 1; i <= n; i++) {

	}*/
	for (int i = 2; i <= n; i += 2) {
		t = (t + 1) % (k + 1);
		if (t == 0)
			t++;
		for (int j = n; j - t >= 1; j--) {
			a[j][i] = a[j - t][i];
		}
		for (int j = 1; j <= t; j++) {
			a[j][i] = x;
		}
	}
}
int main() {
	
	cin >> n>>k>>x;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cin >> a[i][j];
		}
	}
	solve();
	int res = 0;
	for (int i = 1; i <= n; i++) {
		res = 0;
		for (int j = 1; j <= n; j++) {
			
			res += a[i][j];
			
		}
		if (i != 1) cout << " ";
		cout << res ;
	}
	
}
凉心哥哥的小宝藏 文章被收录于专栏

c++

全部评论
#include <bits> using namespace std; int n, k, x; const int N = 110; int a[N][N]; void solve() { int t = 0; for (int i = 2; i <= n; i += 2) { t = (t + 1) % (k + 1); if (t == 0) t = 1; for (int j = n; j-t>=1; j--) { a[j][i] = a[j - t][i]; } for (int j = 1; j <= t; j++) { a[j][i] = x; } } } int main() { cin >> n >> k >> x; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> a[i][j]; } } solve(); int res = 0; for (int i = 1; i <= n; i++) { res = 0; for (int j = 1; j <= n; j++) { res += a[i][j]; } if (i != 1) cout << " "; cout << res; } }</bits>
点赞 回复 分享
发布于 2022-04-22 18:33

相关推荐

牛客97567122...:我最近投的几个,都是要不已读不回,要不不回,还有直接拒绝的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务