Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4.  
  5. unsigned int N=3;
  6.  
  7. int comp(unsigned int N){
  8. char *c_pole1=malloc(sizeof (char)*(N+1));
  9. char *c_pole2=malloc(sizeof (char)*(N+1));
  10. unsigned int c1_i=0;
  11. unsigned int c2_i=0;
  12. unsigned int a=0;
  13. int x=0; //pocet opakujicih se celku
  14. int p;
  15. int o=0; //jesli se opakuje o=1, neopakuje o=0
  16.  
  17. for(c1_i=0; c1_i<N; c1_i++){     //(c1_i<N) ? (c1_i == N)     ????????
  18.         p=getchar();
  19.         c_pole1[c1_i]=p;
  20.         while((p=getchar())==EOF){
  21.             printf("Neocekavany konec vstupu\n");
  22.             return(0); //tady bude chybovy kod
  23.         }
  24.     }
  25. for(c2_i=0; c2_i<N; c2_i++){
  26.         p=getchar();
  27.         c_pole2[c2_i]=p;
  28.         while((p=getchar())==EOF){
  29.             printf("Neocekavany konec vstupu\n");
  30.             return(0); //tady bude chybovy kod
  31.         }
  32.     }
  33. do{
  34.     for(a=o; a<N; a++){
  35.         if(c_pole1[c1_i] == c_pole2[c2_i]){
  36.             o=1;
  37.         }
  38.     }
  39.  
  40.  
  41.     if(o==1){
  42.         x++;
  43.         c_pole1[c1_i%N]=c_pole2[c2_i%N];
  44.         for(c2_i=0; c2_i<N; c2_i++){
  45.         p=getchar();
  46.         c_pole2[c2_i]=p;
  47.         while((p=getchar())==EOF){
  48.             printf("Neocekavany konec vstupu\n");
  49.             return(0); //tady bude chybovy kod
  50.             }
  51.         }
  52.     }
  53.  
  54.     if(o==0 && x==0){
  55.         putchar(c_pole1[0]);
  56.         c_pole1[c1_i%N]=c_pole1[(c1_i+1)%N];
  57.         c_pole1[c1_i%N]=c_pole2[0];
  58.         // c_pole2[c1_i+1]=c_pole1[(c2_i)]; //"???
  59.         c_pole2[c2_i%N]=c_pole2[(c2_i+1%N)];
  60.         p=getchar();
  61.         while((p=getchar())==EOF){
  62.             printf("Neocekavany konec vstupu\n");
  63.         return(0); //tady bude chybovy kod
  64.         }
  65.         c_pole2[(c2_i%N)]=p;
  66.         }
  67.  
  68.     }
  69.  
  70.     if(o==0 && x != 0){
  71.         putchar(x);
  72.         for(c1_i=0; c1_i<N; c1_i++){
  73.             putchar(c_pole1[c1_i]);
  74.         }
  75.  
  76.  
  77.     }
  78.  
  79.  
  80.     }while((p=getchar()) != EOF);
  81.     free(c_pole1);
  82.     free(c_pole2);
  83. return(0);
  84. }
  85.  
  86.  
  87.  
  88. int main()
  89. {
  90.     comp(N);
  91.     return (0);
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement