• USACO section1.2 Transformation


      1 /*
      2 ID: vincent63
      3 LANG: C
      4 TASK: transform
      5 */
      6 #include <stdio.h>
      7 #include<stdlib.h>
      8 #include<string.h>
      9 static char a[10][10];
     10 static char b[10][10];
     11 static char temp[10][10];
     12 static char temp2[10][10];
     13 static int n;
     14 //return 1 if can be done; 
     15 //return 0,if cant be done;
     16 //90
     17 int first_tran(){
     18     int ret=1;
     19     int i,j;
     20           
     21     for(i=0;i<n;i++){
     22         for(j=0;j<n;j++){
     23             temp2[j][n-1-i]=temp[i][j];
     24             if(a[i][j]!=b[j][n-1-i]){
     25                 ret=0;
     26                 //printf("not match (%d,%d) %c (%d,%d) %c
    ",i,j,a[i][j],j,n-1-i,b[j][n-i]);
     27             }
     28         }
     29     }    
     30     return ret;
     31 }
     32 //180
     33 int second_tran(){
     34     int ret=1;
     35     int i,j;
     36           
     37     for(i=0;i<n;i++){
     38         for(j=0;j<n;j++){
     39             temp2[n-1-i][n-1-j]=temp[i][j];
     40             if(a[i][j]!=b[n-1-i][n-1-j]){
     41                 ret=0;
     42                 //printf("not match (%d,%d) %c (%d,%d) %c
    ",i,j,a[i][j],n-1-i,n-1-j,b[n-1-i][n-1-j]);
     43             }
     44         }
     45     }    
     46     return ret;
     47 }
     48 //270
     49 int third_tran(){
     50     int ret=1;
     51     int i,j;
     52           
     53     for(i=0;i<n;i++){
     54         for(j=0;j<n;j++){
     55             temp2[n-1-j][i]=temp[i][j];
     56             if(a[i][j]!=b[n-1-j][i]){
     57                 ret=0;
     58                 //printf("not match (%d,%d) %c (%d,%d) %c
    ",i,j,a[i][j],n-1-j,i,b[n-1-j][i]);
     59             }
     60         }
     61     }    
     62     return ret;
     63 }
     64 
     65 //mirror
     66 int fouth_tran(){
     67     int ret=1;
     68     int i,j;
     69           
     70     for(i=0;i<n;i++){
     71         for(j=0;j<n;j++){
     72             temp[i][n-1-j]=a[i][j];
     73             if(a[i][j]!=b[i][n-1-j]){
     74                 ret=0;
     75                 //printf("not match (%d,%d) %c (%d,%d) %c
    ",i,j,a[i][j],i,n-1-j,b[i][n-1-j]);
     76             }
     77         }
     78     }    
     79     return ret;
     80 }
     81 int is_equal(){
     82     int ret=1;
     83     int i,j;
     84           
     85     for(i=0;i<n;i++){
     86         for(j=0;j<n;j++){
     87             if(temp2[i][j]!=b[i][j]){
     88                 ret=0;
     89                 //printf("not match (%d,%d) %c (%d,%d) %c
    ",i,j,a[i][j],i,j,b[i][j]);
     90             }
     91         }
     92     }    
     93     return ret;
     94 }
     95 //combine
     96 int fifth_tran(){
     97     int i,j;
     98     fouth_tran();
     99     first_tran();
    100     if(is_equal()){
    101         return 1;
    102     }
    103     
    104     printf("
    ");
    105     for(i=0;i<n;i++){
    106           for(j=0;j<n;j++){
    107             printf("%c",temp2[i][j]);
    108         }
    109         printf("
    ");            
    110     }
    111     
    112     fouth_tran();
    113     second_tran();
    114     if(is_equal()){
    115         return 1;
    116     }
    117     printf("
    ");
    118     for(i=0;i<n;i++){
    119         for(j=0;j<n;j++){
    120             printf("%c",temp2[i][j]);
    121         }
    122         printf("
    ");            
    123     }
    124     
    125     fouth_tran();
    126     third_tran();
    127     if(is_equal()){
    128         return 1;
    129     }
    130     printf("
    ");
    131     for(i=0;i<n;i++){
    132         for(j=0;j<n;j++){
    133             printf("%c",temp2[i][j]);
    134         }
    135         printf("
    ");            
    136     }
    137     
    138     return 0;    
    139 }
    140 //no change
    141 int sixth_tran(){
    142     int ret=1;
    143     int i,j;
    144           
    145     for(i=0;i<n;i++){
    146         for(j=0;j<n;j++){
    147             if(a[i][j]!=b[i][j]){
    148                 ret=0;
    149                 //printf("not match (%d,%d) %c (%d,%d) %c
    ",i,j,a[i][j],i,j,b[i][j]);
    150             }
    151         }
    152     }    
    153     return ret;
    154 }
    155 int test_tran(){
    156     if(first_tran()){
    157         return 1;
    158     }else if(second_tran()){
    159         return 2;
    160     }else if(third_tran()){
    161         return 3;
    162     }else if(fouth_tran()){
    163         return 4;
    164     }else if(fifth_tran()){
    165         return 5;
    166     }else if(sixth_tran()){
    167         return 6;
    168     }
    169     return 7;
    170 }
    171 
    172 int main () {
    173     FILE *fin  = fopen ("transform.in", "r");
    174     FILE *fout = fopen ("transform.out", "w");
    175     
    176     int i,j,ret;
    177     char buf[10];
    178     char buf2[20];
    179     
    180     fgets(buf,10,fin);
    181     n=atoi(buf); 
    182        
    183     for(i=0;i<n;i++){        
    184         fgets(buf2,20,fin);
    185         strcpy(a[i],buf2);            
    186     }
    187     for(i=0;i<n;i++){      
    188         fgets(buf2,20,fin);
    189         strcpy(b[i],buf2);        
    190     }
    191     
    192     for(i=0;i<n;i++){
    193         for(j=0;j<n;j++){
    194             printf("%c",a[i][j]);
    195         }
    196         printf("
    ");            
    197     }
    198     for(i=0;i<n;i++){
    199         for(j=0;j<n;j++){
    200             printf("%c",b[i][j]);
    201         }
    202         printf("
    ");            
    203     }
    204     
    205     ret=test_tran();
    206     
    207     char res[10];
    208     sprintf(res,"%d
    ",ret);
    209     fputs(res,fout);
    210     printf("%d",ret);
    211     return 0;
    212 }
  • 相关阅读:
    Scala实验二——3.统计学生成绩
    Scala实验二——2.模拟图形绘制
    Scala实验二——1.计算级数
    Scala类和对象笔记
    《能力陷阱》反思
    spark学习
    Ajax获取后台Servlet数据
    在进行pip安装时报错:Could not fetch URL https://pypi.org/simple/xrld/: There was a problem confirming the ssl certificate:
    pycharm连接服务器的内部环境时出错,输入用户密码之后报错:Permission denied, please try again authentication failed
    pycharm连接docker服务器遇到的错误:java.net.ConnectException: Connection refused
  • 原文地址:https://www.cnblogs.com/houshengtao/p/6102819.html
Copyright © 2020-2023  润新知