#19681: 想知道為何第五筆過不了


aaaaa123 (unknown)

學校 : 不指定學校
編號 : 89844
來源 : [137.132.26.94]
最後登入時間 :
2024-04-23 20:26:35
b266. 矩陣翻轉 -- 2016 APCS 實作題第二題 | From: [61.231.156.224] | 發表日期 : 2019-10-20 01:51

#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
void turn(int a[100][100],int b,int c)
{
int aa[b*c];
int p=0;
for(int r=0;r<c;r++)
for(int t=b-1;t>=0;t--)
{
aa[p]=a[t][r];
p++;
}
p=0;
for(int t=0;t<c;t++)
for(int r=0;r<b;r++)
{a[t][r]=aa[p];
p++;}
}
void flip(int a[100][100],int b,int c)
{
int aa[b*c];
int p=0;
for(int r=b-1;r>=0;r--)
for(int k=0;k<=c-1;k++)
{
aa[p]=a[r][k];
p++;
}
p=0;
for(int r=0;r<b;r++)
for(int t=0;t<c;t++)
{a[r][t]=aa[p];
p++;}
}
int main()
{
int a,b,c;
cin >> a>>b>>c;
int tem[c];
int t[100][100];
memset(t,0,sizeof(t));
for(int r=0;r<a;r++)
{
for(int k=0;k<b;k++)
cin>>t[r][k];
}
for(int r=0;r<c;r++)
cin>>tem[r];
for(int r=0;r<c;r++)
{
if(tem[r]==0)
{
turn(t,a,b);
swap(a,b);
}
else
flip(t,a,b);
}
cout<<a<<" "<<b<<endl;
for(int w=0;w<a;w++)
{
for(int r=0;r<b;r++)
cout<<t[w][r]<<" ";
cout<<endl;
}
}

 
ZeroJudge Forum