当前位置:网站首页>方阵循环右移
方阵循环右移
2022-06-22 08:02:00 【好好学吧867】
本题要求编写程序,将给定n×n方阵中的每个元素循环向右移m个位置,即将第0、1、⋯、n−1列变换为第n−m、n−m+1、⋯、n−1、0、1、⋯、n−m−1列。
输入格式:
输入第一行给出两个正整数m和n(1≤n≤6)。接下来一共n行,每行n个整数,表示一个n阶的方阵。
输出格式:
按照输入格式输出移动后的方阵:即输出n行,每行n个整数,每个整数后输出一个空格。
输入样例:
2 3
1 2 3
4 5 6
7 8 9
输出样例:
2 3 1
5 6 4
8 9 7 代码:
#include <stdio.h>
int main(){
int n,m;
scanf("%d%d",&m,&n);
int a[n][n],b[n][n];
int i,j;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
scanf("%d",&a[i][j]);
}
for(j=0;j<n;j++){
b[i][(j+m)%n]=a[i][j];
}
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(j==n-1&&i==n-1)printf("%d ",b[i][j]);
else if(j!=n-1)printf("%d ",b[i][j]);
else if(j==n-1&&i!=n-1)printf("%d \n",b[i][j]);
}
}
}边栏推荐
- Chmod Chmod command
- ConfigManager JsonToObject
- Microsoft Remote Desktop 10.7.6正式版
- MySQL avoids the method of repeatedly inserting records (ignore, replace, on duplicate key update)
- SQL server changes the primary key index to a non clustered index
- How Navicat queries the password information of the connected database
- XMIND 2022 mind map active resources?
- Submit values of various inputs of the form
- Mt4/mql4 getting started to proficient in foreign exchange EA automatic trading tutorial - common functions of MQL language
- LNMP environment setup
猜你喜欢

Canvastotempfilepath of wechat

Website sharing of program ape -- continuous update

An example shows the difference between let and VaR

对于mysql中数据为NULL引发的一些问题和思考
![[Oracle database] mammy tutorial day14 conversion function](/img/ef/c468316750c57212a067abd00a10e9.png)
[Oracle database] mammy tutorial day14 conversion function

MySQL 8.0 under Linux forgets the password

【Oracle 数据库】奶妈式教程 day12 字符函数

QT QtableView的使用示例

mysql查询group by 1055 问题完美解决,最简单最便捷的方法

模板代码概述
随机推荐
(7)双向链表
对于mysql中数据为NULL引发的一些问题和思考
Upload your own library to pod
Xlua environment configuration
Mt4/mql4 getting started to mastering EA tutorial lesson 5 - common functions of MQL language (V) - common functions of account information
Mt4/mql4 getting started to be proficient in EA tutorial lesson 7 - common functions of MQL language (VII) - index value taking function
MySQL 8.0 under Linux forgets the password
充电宝的玄机
[Oracle database] wet nurse tutorial day15 DDL, DML, index, view, sequence and deadlock are enough
数据可视化优秀案例
Symbolic processing of crash log
AutoCAD 2020.3中文版 (旧版本)
LNMP environment setup
MySQL avoids the method of repeatedly inserting records (ignore, replace, on duplicate key update)
Modular import and export collation in JS
Restrict input type (multiple methods)
面试突击59:一个表中可以有多个自增列吗?
AudioQueue
Fmdb usage details mark
Excellent cases of data visualization