杭电2135:测试数据都对,为啥WA,可否提供多一些的数据,求大牛~谢啦

#include<stdio.h>voidmain(){chara[10][10],b[10][10],c;longn,m,i,j,t;while(scanf("%ld%... #include<stdio.h>
void main()
{
char a[10][10],b[10][10],c;
long n,m,i,j,t;
while(scanf("%ld%ld",&n,&m)!=EOF)
{
getchar();
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
scanf("%c",&a[i][j]);
getchar();
}
if(m<0)
{
m=-m;
t=4-m%4; /*m转化为0,1,2,3四种情况,只有四种情况呀!*/
}
else
t=m%4;
if(t==0)
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%c",a[i][j]);
printf("\n");
}
}
if(t==1)
{
for(i=0;i<n;i++)
for(j=0;j<n;j++)
b[j][n-1-i]=a[i][j];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%c",b[i][j]);
printf("\n");
}
}
if(t==2)
{
for(i=0;i<n;i++)
for(j=0;j<n;j++)
b[n-i-1][n-j-1]=a[i][j];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%c",b[i][j]);
printf("\n");
}
}
if(t==3)
{
for(i=0;i<n;i++)
for(j=0;j<n;j++)
b[n-1-j][i]=a[i][j];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%c",b[i][j]);
printf("\n");
}
}
}
}
http://acm.hdu.edu.cn/showproblem.php?pid=2135
展开
 我来答
百度网友c2a621b0f
2012-02-07 · 超过41用户采纳过TA的回答
知道小有建树答主
回答量:98
采纳率:0%
帮助的人:92.4万
展开全部
AC代码如下。

#include <iostream>

using namespace std;

char roate_tbl_even[3][10][10]=
{
{
{90,80,70,60,50,40,30,20,10, 0},
{91,81,71,61,51,41,31,21,11, 1},
{92,82,72,62,52,42,32,22,12, 2},
{93,83,73,63,53,43,33,23,13, 3},
{94,84,74,64,54,44,34,24,14, 4},
{95,85,75,65,55,45,35,25,15, 5},
{96,86,76,66,56,46,36,26,16, 6},
{97,87,77,67,57,47,37,27,17, 7},
{98,88,78,68,58,48,38,28,18, 8},
{99,89,79,69,59,49,39,29,19, 9}
},//90-degrees
{
{99,98,97,96,95,94,93,92,91,90},
{89,88,87,86,85,84,83,82,81,80},
{79,78,77,76,75,74,73,72,71,70},
{69,68,67,66,65,64,63,62,61,60},
{59,58,57,56,55,54,53,52,51,50},
{49,48,47,46,45,44,43,42,41,40},
{39,38,37,36,35,34,33,32,31,30},
{29,28,27,26,25,24,23,22,21,20},
{19,18,17,16,15,14,13,12,11,10},
{ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
},//180-degrees
{
{ 9,19,29,39,49,59,69,79,89,99},
{ 8,18,28,38,48,58,68,78,88,98},
{ 7,17,27,37,47,57,67,77,87,97},
{ 6,16,26,36,46,56,66,76,86,96},
{ 5,15,25,35,45,55,65,75,85,95},
{ 4,14,24,34,44,54,64,74,84,94},
{ 3,13,23,33,43,53,63,73,83,93},
{ 2,12,22,32,42,52,62,72,82,92},
{ 1,11,21,31,41,51,61,71,81,91},
{ 0,10,20,30,40,50,60,70,80,90},
}//270-degrees
};

char roate_tbl_odd[3][10][10]=
{
{
{72,63,54,45,36,27,18, 9, 0, 0},
{73,64,55,46,37,28,19,10, 1, 0},
{74,65,56,47,38,29,20,11, 2, 0},
{75,66,57,48,39,30,21,12, 3, 0},
{76,67,58,49,40,31,22,13, 4, 0},
{77,68,59,50,41,32,23,14, 5, 0},
{78,69,60,51,42,33,24,15, 6, 0},
{79,70,61,52,43,34,25,16, 7, 0},
{80,71,62,53,44,35,26,17, 8, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
},//90-degrees
{
{80,79,78,77,76,75,74,73,72, 0},
{71,70,69,68,67,66,65,64,63, 0},
{62,61,60,59,58,57,56,55,54, 0},
{53,52,51,50,49,48,47,46,45, 0},
{44,43,42,41,40,39,38,37,36, 0},
{35,34,33,32,31,30,29,28,27, 0},
{26,25,24,23,22,21,20,19,18, 0},
{17,16,15,14,13,12,11,10, 9, 0},
{ 8, 7, 6, 5, 4, 3, 2, 1, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
},//180-degrees
{
{ 8,17,26,35,44,53,62,71,80, 0},
{ 7,16,25,34,43,52,61,70,79, 0},
{ 6,15,24,33,42,51,60,69,78, 0},
{ 5,14,23,32,41,50,59,68,77, 0},
{ 4,13,22,31,40,49,58,67,76, 0},
{ 3,12,21,30,39,48,57,66,75, 0},
{ 2,11,20,29,38,47,56,65,74, 0},
{ 1,10,19,28,37,46,55,64,73, 0},
{ 0, 9,18,27,36,45,54,63,72, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
}//270-degrees
};
// 1 2 3 4 5 6 7 8 9 10
const int start_pos[11]={0,4,4,3,3,2,2,1,1,0,0};

void input_data(void* target_, int n);
void output_data(void* target_, int n);

int main()
{

char pre_buff[150]={0};
char pre_buff2[150]={0};

char (*in_even)[10]=(char (*)[10])pre_buff;
char (*in_odd)[9]=(char (*)[9])pre_buff;
char (*res_even)[10]=(char (*)[10])pre_buff2;
char (*res_odd)[9]=(char (*)[9])pre_buff2;

int n, c;

while(1)
{
if ((cin>>n>>c).eof()) break;

c = (c&0x03)-1;

if (n%2 == 0)
{
input_data(in_even, n);
if (c == -1)
{
output_data(in_even, n);
continue;
}
char *inp_ = (char*)in_even;
for (int i=start_pos[n]; i<start_pos[n]+n; i++)
{
for (int j=start_pos[n]; j<start_pos[n]+n; j++)
{
res_even[i][j] = inp_[roate_tbl_even[c][i][j]];
}
}
output_data(res_even, n);
}
else
{
input_data(in_odd, n);
if (c == -1)
{
output_data(in_odd, n);
continue;
}
char *inp_ = (char*)in_odd;
for (int i=start_pos[n]; i<start_pos[n]+n; i++)
{
for (int j=start_pos[n]; j<start_pos[n]+n; j++)
{
res_odd[i][j] = inp_[roate_tbl_odd[c][i][j]];
}
}
output_data(res_odd, n);
}
}

return 0;
}

void input_data(void* target_, int n)
{
char (*target_even)[10] = (char (*)[10])target_;
char (*target_odd)[9] = (char (*)[9])target_;
int start_pos_ = start_pos[n];
for (int i=0; i<n; i++)
{
if (n%2 !=0) cin>>&(target_odd[start_pos_+i][start_pos_]);
else cin>>&(target_even[start_pos_+i][start_pos_]);
}
}

void output_data(void* target_, int n)
{
char (*target_even)[10] = (char (*)[10])target_;
char (*target_odd)[9] = (char (*)[9])target_;
int start_pos_ = start_pos[n];
for (int i=0; i<n; i++)
{
if (n%2!=0) cout.write(&(target_odd[start_pos_+i][start_pos_]), n);
else cout.write(&(target_even[start_pos_+i][start_pos_]), n);
cout<<endl;
}
}
追问
我用的是C,C++还没学,还有能不能在我的代码上改,或是说下你的思路~O(∩_∩)O谢谢哈~~
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2012-02-06
展开全部
跑堂
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式