Advertisement
Stefan1999

3G4Z

Jun 16th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7.     int i, j, n, m = 0, k = 0, brChar = 0, z = 0, l, ds = 0, obrnuto = 0;
  8.     char str[100], dstr[100], mat[100][100], prviKarakter[1], desstr[100];
  9.  
  10.     printf("Unesite string:\n---> ");
  11.     gets(str);
  12.  
  13.     for(i=0; i<strlen(str); i++) {
  14.         if(str[i] == ' ') {
  15.             str[i] = '_';
  16.         }
  17.     }
  18.  
  19.     prviKarakter[0] = str[0];
  20.  
  21.     n = atoi(prviKarakter);
  22.  
  23.     strcpy(str, str+1);
  24.  
  25.     for(j=0; j<strlen(str); j++) {
  26.         for(i=0; i<n; i++) {
  27.             mat[i][j] = str[m];
  28.             m++;
  29.         }
  30.     }
  31.  
  32.     for(j=0; j<(float)strlen(str)/n; j++) {
  33.         if(z == 0) {
  34.             for(i=0; i<n; i++) {
  35.                 dstr[k] = mat[i][j];
  36.                 k++;
  37.             }
  38.             k = 0;
  39.             z = 1;
  40.  
  41.             strncpy(dstr, dstr+brChar, n-2*brChar);
  42.  
  43.             for(l=0; l<n-2*brChar; l++) {
  44.                 desstr[ds] = dstr[l];
  45.                 ds++;
  46.             }
  47.  
  48.             if(obrnuto == 0) {
  49.                 if(n-2*brChar > 1)
  50.                     brChar++;
  51.                 else {
  52.                     obrnuto = 1;
  53.                     brChar--;
  54.                 }
  55.             } else {
  56.                 if(n-2*brChar < n-1)
  57.                     brChar--;
  58.                 else {
  59.                     obrnuto = 0;
  60.                     brChar++;
  61.                 }
  62.             }
  63.  
  64.         } else if(z == 1){
  65.             for(i=n-1; i>=0; i--) {
  66.                 dstr[k] = mat[i][j];
  67.                 k++;
  68.             }
  69.             k = 0;
  70.             z = 0;
  71.  
  72.             strncpy(dstr, dstr+brChar, n-2*brChar);
  73.  
  74.             for(l=0; l<n-2*brChar; l++) {
  75.                 desstr[ds] = dstr[l];
  76.                 ds++;
  77.             }
  78.  
  79.             if(obrnuto == 0) {
  80.                 if(n-2*brChar > 1)
  81.                     brChar++;
  82.                 else {
  83.                     obrnuto = 1;
  84.                     brChar--;
  85.                 }
  86.             } else {
  87.                 if(n-2*brChar < n-1)
  88.                     brChar--;
  89.                 else {
  90.                     obrnuto = 0;
  91.                     brChar++;
  92.                 }
  93.             }
  94.         }
  95.     }
  96.  
  97.     for(i=0; i<strlen(desstr); i++) {
  98.         if(desstr[i] == '_') {
  99.             desstr[i] = ' ';
  100.         }
  101.     }
  102.     printf("\nDesifrovan string:\n---> ");
  103.     puts(desstr);
  104.      /* printf("ovo je matrica") */
  105.     /*
  106.     for(i=0; i<n; i++) {
  107.         for(j=0; j<(float)strlen(str)/n; j++) {
  108.             printf("%c ", mat[i][j]);
  109.         }
  110.         printf("\n");
  111.     }
  112.     */
  113.  
  114.     return 0;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement