DanikKUL

Умножение кубов(алгоритм Рота)

Mar 3rd, 2022 (edited)
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char* umnoz(char* el1, char* el2){
  6.     int length = strlen(el1);
  7.     char *res = (char*) calloc(30, sizeof (char));
  8.     for (int i = 0; i < length; ++i) {
  9.         if(el1[i] == el2[i]){
  10.             res[i] = el1[i];
  11.         } else if(el1[i] != el2[i] && el1[i] != 'x' && el2[i] != 'x'){
  12.             res[i] = 'y';
  13.         } else if(el1[i] != el2[i] && (el1[i] == 'x' || el2[i] != 'x')){
  14.             res[i] = el2[i];
  15.         } else if(el1[i] != el2[i] && (el1[i] != 'x' || el2[i] == 'x')){
  16.             res[i] = el1[i];
  17.         }
  18.     }
  19.     return res;
  20. }
  21.  
  22. int main() {
  23.     int amount;
  24.  
  25.     printf("enter amount of elements\n");
  26.     scanf("%d", &amount);
  27.  
  28.     char* elements[amount];
  29.     char* table[amount][amount];
  30.  
  31.     for (int i = 0; i < amount; ++i) {
  32.         elements[i] = (char*) calloc(50, sizeof (char));
  33.     }
  34.  
  35.     getchar();
  36.     for (int i = 0; i < amount; ++i) {
  37.         printf("enter element #%d\n", i + 1);
  38.         fflush(stdin);
  39.         gets(elements[i]);
  40.     }
  41.  
  42.     for (int i = 0; i < amount; ++i) {
  43.         for (int j = 0; j < amount; ++j) {
  44.             table[i][j] = (char*) calloc(50, sizeof (char));
  45.         }
  46.     }
  47.  
  48.     for (int i = 0; i < amount; ++i) {
  49.         for (int j = 0; j < amount; ++j) {
  50.             table[i][j] = umnoz(elements[i], elements[j]);
  51.         }
  52.     }
  53.  
  54.     for (int i = 0; i < amount; ++i) {
  55.         for (int j = i; j < amount; ++j) {
  56.             table[i][j] = "-----";
  57.         }
  58.     }
  59.  
  60.     for (int i = 0; i < amount; ++i) {
  61.         printf("%s:\t", elements[i]);
  62.         for (int j = 0; j < amount; ++j) {
  63.             printf("%s\t", table[i][j]);
  64.         }
  65.         printf("\n-----------------------------------------\n");
  66.     }
  67.  
  68.  
  69.     return 0;
  70. }
  71.  
Add Comment
Please, Sign In to add comment