Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main()
- {
- int i, j, n, m = 0, k = 0, brChar = 0, z = 0, l, ds = 0, obrnuto = 0;
- char str[100], dstr[100], mat[100][100], prviKarakter[1], desstr[100];
- printf("Unesite string:\n---> ");
- gets(str);
- for(i=0; i<strlen(str); i++) {
- if(str[i] == ' ') {
- str[i] = '_';
- }
- }
- prviKarakter[0] = str[0];
- n = atoi(prviKarakter);
- strcpy(str, str+1);
- for(j=0; j<strlen(str); j++) {
- for(i=0; i<n; i++) {
- mat[i][j] = str[m];
- m++;
- }
- }
- for(j=0; j<(float)strlen(str)/n; j++) {
- if(z == 0) {
- for(i=0; i<n; i++) {
- dstr[k] = mat[i][j];
- k++;
- }
- k = 0;
- z = 1;
- strncpy(dstr, dstr+brChar, n-2*brChar);
- for(l=0; l<n-2*brChar; l++) {
- desstr[ds] = dstr[l];
- ds++;
- }
- if(obrnuto == 0) {
- if(n-2*brChar > 1)
- brChar++;
- else {
- obrnuto = 1;
- brChar--;
- }
- } else {
- if(n-2*brChar < n-1)
- brChar--;
- else {
- obrnuto = 0;
- brChar++;
- }
- }
- } else if(z == 1){
- for(i=n-1; i>=0; i--) {
- dstr[k] = mat[i][j];
- k++;
- }
- k = 0;
- z = 0;
- strncpy(dstr, dstr+brChar, n-2*brChar);
- for(l=0; l<n-2*brChar; l++) {
- desstr[ds] = dstr[l];
- ds++;
- }
- if(obrnuto == 0) {
- if(n-2*brChar > 1)
- brChar++;
- else {
- obrnuto = 1;
- brChar--;
- }
- } else {
- if(n-2*brChar < n-1)
- brChar--;
- else {
- obrnuto = 0;
- brChar++;
- }
- }
- }
- }
- for(i=0; i<strlen(desstr); i++) {
- if(desstr[i] == '_') {
- desstr[i] = ' ';
- }
- }
- printf("\nDesifrovan string:\n---> ");
- puts(desstr);
- /* printf("ovo je matrica") */
- /*
- for(i=0; i<n; i++) {
- for(j=0; j<(float)strlen(str)/n; j++) {
- printf("%c ", mat[i][j]);
- }
- printf("\n");
- }
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement