1472: [蓝桥杯2019初赛]旋转 【简单】

在这里插入图片描述
http://oj.ecustacm.cn/problem.php?id=1472

解析: 就是一个找坐标变化规律的题目

#include<cstdio>
#include<iostream>
using namespace std;
int main(void)
{
    
    
	int a,b;
	int i,j;
	cin>>a>>b;
	int str[a][b];
	for(i=0;i<a;i++)
	{
    
    
		for(j=0;j<b;j++)
		{
    
    
			cin>>str[i][j]; 
		}
	}
	int str1[b][a];
	for(i=0;i<a;i++)
	{
    
    
		for(j=0;j<b;j++)
		{
    
    
			str1[j][a-1-i]=str[i][j];
		}
	}
	for(i=0;i<b;i++)
	{
    
    
		for(j=0;j<a;j++)
		{
    
    
			printf("%d ",str1[i][j]);
		}
		printf("\n");
	}
	return 0;
}

更简单的写法:

#include <stdio.h>
int n,m;
int a[100][100];
int main()
{
    
    	int i,j;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
			scanf("%d",&a[i][j]);
	for(j=0;j<m;j++)
		{
    
    
		for(i=n-1;i>=0;i--)
		 printf("%d ",a[i][j]);	
		 printf("\n");
		}
		 return 0;
}

猜你喜欢

转载自blog.csdn.net/bettle_king/article/details/115263956