ccyy's coding zone
往前走,不要留恋路边的风景.
posts - 25,comments - 9,trackbacks - 0
最近准备搞搞模拟,这题还是比较简单的,题目让你做什么就做什么,但还是WA了一次,因为未填满的空格都要用大写则目A到Z填满,不过2000+B搞定还是比较有成就的.....
丑陋的代码~~
   

  1 #include<stdio.h>
  2 #include<string.h>
  3 #include<stdlib.h>
  4 char key[90],str[10001];
  5     int a[101][101],n,i,j,k,m,l1,l,temp;
  6     
  7 int main()
  8 {
  9 
 10     while(scanf("%s",key)!=EOF)
 11     {
 12         memset(a,0,sizeof(a));
 13         memset(str,0,sizeof(str));
 14         getchar();
 15         gets(str);
 16         
 17         n=(key[0]-'0')*10+key[1]-'0';
 18         if(n==0)
 19         n=100;
 20         l1=strlen(key);
 21         l=strlen(str);
 22         m=0;
 23         int th=0;
 24         for(i=1;i<=n;i++)
 25             for(j=1;j<=n;j++)
 26             {
 27                 if(m>=l)
 28                 {
 29                     if(th==26)
 30                     th-=26;
 31                     a[i][j]=th++;
 32                     continue;
 33                     }
 34                 if(str[m]==' ')
 35                 a[i][j]=-1;
 36                 else if(str[m]>='a'&&str[m]<='z')
 37                 a[i][j]=str[m]-'a';
 38                 else
 39                 a[i][j]=str[m]-'A';
 40                 m++;
 41                 }
 42         for(i=2;i<l1;i++)
 43         {
 44             if(key[i]=='S')
 45             {
 46                 for(j=1;j<=n;j+=2)
 47                 {
 48                     temp=a[1][j];
 49                     for(k=1;k<n;k++)
 50                     a[k][j]=a[k+1][j];
 51                     
 52                     a[n][j]=temp;
 53                 }
 54                 
 55             
 56                 for(j=2;j<=n;j+=2)
 57                 {
 58                     temp=a[n][j];
 59                     for(k=n;k>1;k--)
 60                     {
 61                         a[k][j]=a[k-1][j];
 62                         }
 63                     a[1][j]=temp;
 64                     }
 65             }
 66             else if(key[i]=='R')
 67             {
 68                 for(j=1;j<=n;j+=2)
 69                 {
 70                     temp=a[j][n];
 71                     for(k=n;k>1;k--)
 72                         a[j][k]=a[j][k-1];
 73                     a[j][1]=temp;
 74                     }
 75                 for(j=2;j<=n;j+=2)
 76                 {
 77                     temp=a[j][1];
 78                     for(k=1;k<n;k++)
 79                     a[j][k]=a[j][k+1];
 80                     a[j][n]=temp;
 81                     }
 82                 }
 83             else if(key[i]=='L')
 84             {
 85                 for(j=1;j*2<=n;j+=2)
 86                 {
 87                     temp=a[j][j];
 88                     for(k=j;k<n-(j-1);k++)
 89                     a[k][j]=a[k+1][j];
 90                     for(k=j;k<n-(j-1);k++)
 91                     a[n-(j-1)][k]=a[n-(j-1)][k+1];
 92                     for(k=n-(j-1);k>j;k--)
 93                     a[k][n-(j-1)]=a[k-1][n-(j-1)];
 94                     for(k=n-(j-1);k>j;k--)
 95                     a[j][k]=a[j][k-1];
 96                     a[j][j+1]=temp;
 97                     }
 98                 for(j=2;j*2<=n;j+=2)
 99                 {
100                     temp=a[j][j];
101                     for(k=j;k<n-(j-1);k++)
102                     a[j][k]=a[j][k+1];
103                     for(k=j;k<n-(j-1);k++)
104                     a[k][n-(j-1)]=a[k+1][n-(j-1)];
105                     for(k=n-(j-1);k>j;k--)
106                     a[n-(j-1)][k]=a[n-(j-1)][k-1];
107                     for(k=n-(j-1);k>j;k--)
108                     a[k][j]=a[k-1][j];
109                     a[j+1][j]=temp;
110                     }
111             }
112         
113         }
114         for(i=1;i<=n;i++)
115             for(j=1;j<=n;j++)
116             {
117                 if(a[i][j]==-1)
118                 printf(" ");
119                 else
120                 printf("%c",a[i][j]+'A');
121                 }
122                 printf("\n");
123     }
124     
125     return 0;
126     
127     }
posted on 2009-11-23 21:09 ccyy 阅读(158) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理