Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.59 KB | None | 0 0
  1. int comp(unsigned int N){
  2. char *c_pole1=malloc(sizeof (char)*(N+1));
  3. char *c_pole2=malloc(sizeof (char)*(N+1));
  4. unsigned long o=1;
  5. unsigned long q=0;
  6. char c=0;
  7. char d=0;
  8. int x=0;
  9. unsigned long d1_i=0;
  10. unsigned long d2_i=0;
  11. memset(c_pole1, 0, sizeof(char)*(N+1));
  12. memset(c_pole2, 0, sizeof(char)*(N+1)); //nulovani pole
  13.  
  14. for(d1_i=0; d1_i<N; d1_i++){
  15.     c = getchar();
  16.     if(c == '\n')
  17.     {
  18.         q=1;
  19.     }
  20.     c_pole1[d1_i]=c;
  21. }
  22. while(q == 0){
  23.     for(d2_i=0; d2_i<N; d2_i++){
  24.         c = getchar();
  25.         if(c == '\n')
  26.         {
  27.             q=1;
  28.             break;
  29.         }
  30.         c_pole2[d2_i]=c;
  31.     }
  32.     if(strcmp(c_pole1, c_pole2) !=0 || ((c_pole2[0])==0)){
  33.         if(o>1){
  34.             d=o+'0';
  35.             putchar(d);
  36.         }
  37.         for(d1_i=0; d1_i<N; d1_i++){
  38.             if(c_pole1[d1_i] == 0){
  39.                 return(0);
  40.             }
  41.             putchar(c_pole1[d1_i]);
  42.         }
  43.         strcpy(c_pole1, c_pole2);
  44.         o = 1;
  45.     }
  46.     else if (strcmp(c_pole1, c_pole2) ==0 && c == '\n'){
  47.         if(o>1){
  48.             d=o+'0';
  49.             putchar(d);  //putchar('0'+(char)o)
  50.         }
  51.         for(d1_i=0; d1_i<N; d1_i++){
  52.             if(c_pole1[d1_i] == 0){
  53.                 return(0);
  54.             }
  55.             putchar(c_pole1[d1_i]);
  56.             x=1;
  57.  
  58.         }
  59.     }
  60.  
  61.     else{
  62.         o++;
  63.     }
  64. }
  65. while((q == 1) && (x == 0)){
  66.     for(d2_i=0; d2_i<N; d2_i++){
  67.         if(c_pole1[d2_i] == 0){
  68.             return(0);
  69.         }
  70.         putchar(c_pole2[d2_i]);
  71.     }
  72.   free(c_pole1);
  73.   free(c_pole2);
  74.   return(0);
  75. }
  76. return(1);
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement