ivolff

L13

May 14th, 2018
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4. #include <stdbool.h>
  5. #include <limits.h>
  6.  
  7. struct EQW {
  8.     int key;
  9.     int count;
  10.     bool inA, inB, inC,is_incializated;
  11. };
  12. typedef struct EQW eqw;
  13.  
  14. eqw *D;
  15. int sizeD;
  16.  
  17. int min(int A, int B) {
  18.     if (A > B)
  19.         return B;
  20.     return A;
  21. }
  22.  
  23. int max(int A, int B) {
  24.     if (A < B)
  25.         return B;
  26.     return A;
  27. }
  28.  
  29. void set_zero(int *array, int size) {
  30.     for (int i = 0; i < size; i++) {
  31.         array[i] = 0;
  32.     }
  33. }
  34.  
  35. void ran(int *array, int size) {
  36.     for (int i = 0; i < size; i++)
  37.         array[i] = rand() % 7 + 12;
  38. }
  39.  
  40. void out(int *array, int size) {
  41.     for (int i = 0; i < size; i++)
  42.         printf("%i", array[i]);
  43. }
  44.  
  45. int serch_min(int *array, int size) {
  46.     int minv = INT_MIN;
  47.     for (int i = 0; i < size; i++)
  48.         minv = min(array[i], minv);
  49.     return minv;
  50. };
  51.  
  52. void serch_equals(int *arrayA, int sizeA, int *arrayB, int sizeB, int *arrayC, int sizeC) {
  53.     sizeD = max(max(sizeA, sizeB), sizeC);
  54.     D = (eqw *) malloc(sizeof(eqw) * (sizeD+1));
  55.     for (int i = 0; i <= sizeD; i++) {
  56.         D[i].key = 0;
  57.         D[i].count = 0;
  58.         D[i].inA = false;
  59.         D[i].inB = false;
  60.         D[i].inC = false;
  61.         D[i].is_incializated=false;
  62.     }
  63.     for (int i = 0; i < sizeA; i++) {
  64.         for (int j = 0; j < sizeD; j++) {
  65.             if (D[j].key == arrayA[i]&&D[i].is_incializated) {
  66.                 if(!D[j].inA)
  67.                     break;
  68.                 D[j].count++;
  69.                 D[j].inA = true;
  70.                 break;
  71.             }
  72.             if(!D[j].is_incializated){
  73.                 D[j].is_incializated=true;
  74.                 D[j].key=arrayA[i];
  75.                 D[j].count++;
  76.                 D[j].inA=true;
  77.                 break;
  78.             }
  79.         }
  80.     }
  81.     for (int i = 0; i < sizeB; i++) {
  82.         for (int j = 0; j < sizeD; j++) {
  83.             if (D[j].key == arrayB[i]&&D[i].is_incializated) {
  84.                 if(!D[j].inB)
  85.                     break;
  86.                 D[j].count++;
  87.                 D[j].inB = true;
  88.                 break;
  89.             }
  90.             if(!D[j].is_incializated){
  91.                 D[j].is_incializated=true;
  92.                 D[j].key=arrayB[i];
  93.                 D[j].count++;
  94.                 D[j].inB=true;
  95.                 break;
  96.             }
  97.         }
  98.     }
  99.     for (int i = 0; i < sizeC; i++) {
  100.         for (int j = 0; j < sizeD; j++) {
  101.             if (D[j].key == arrayC[i]&&D[i].is_incializated) {
  102.                 if(!D[j].inC)
  103.                     break;
  104.                 D[j].count++;
  105.                 D[j].inC = true;
  106.                 break;
  107.             }
  108.             if(!D[j].is_incializated){
  109.                 D[j].is_incializated=true;
  110.                 D[j].key=arrayC[i];
  111.                 D[j].count++;
  112.                 D[j].inC=true;
  113.                 break;
  114.             }
  115.         }
  116.     }
  117. }
  118.  
  119. void out_equals(){
  120.     for(int i=0;i<sizeD;i++){
  121.         printf("%d - %d raz",D[i].key,D[i].count);
  122.     }
  123. }
  124.  
  125. void write(int *array,int size){
  126.     FILE *File = fopen("File.txt", "w");
  127.     fprintf(File,"%d ",size);
  128.     for(int i=0;i<size;i++){
  129.         fprintf(File,"%d ",array[i]);
  130.     }
  131.     fclose(File);
  132. }
  133.  
  134. void read(int *array){
  135.     int size;
  136.     FILE *File = fopen("File.txt", "r");
  137.     fscanf(File,"%d ",&size);
  138.     for(int i=0;i<size;i++){
  139.         fscanf(File,"%d ",&array[i]);
  140.     }
  141.     fclose(File);
  142. }
  143.  
  144. void delete(int* arrayA,int sizeA,int from,int to){
  145.     int * first=(int*)malloc(sizeof(int)*(from-1));
  146.     int * second=(int*)malloc(sizeof(int)*(sizeA-to));
  147.     for(int i=0;i<from-1;i++){
  148.         first[i]=arrayA[i];
  149.     }
  150.     for(int i=to;i<sizeA;i++){
  151.         second[i-to]=arrayA[i];
  152.     }
  153.     arrayA=(int*)malloc(sizeof(int)*(from-1+sizeA-to));
  154.     for(int i=0;i<from-1;i++){
  155.         arrayA[i]=first[i];
  156.     }
  157.     for(int i=from;i<(from-1+sizeA-to);i++){
  158.         arrayA[i]=second[i-from];
  159.     }
  160. }
  161.  
  162. int* incert(int *first,int sizefirst,int *second,int sizesecond,int to){
  163.     int* result=(int*)malloc(sizeof(int)*(sizefirst+sizesecond));
  164.     for(int i=0;i<to;i++){
  165.         result[i]=first[i];
  166.     }
  167.     for(int i=0;i<sizesecond;i++){
  168.         result[i+to]=second[i];
  169.     }
  170.     for(int i=to;i<sizefirst;i++){
  171.         result[sizesecond+i]=first[to+i];
  172.     }
  173.     return result;
  174. }
  175.  
  176. void some_shit(int *array,int size){
  177.     int tmp;
  178.     for(int i=0;i<size/2;i++){
  179.         tmp=array[i];
  180.         array[i]=array[size-i];
  181.         array[size-i]=tmp;
  182.     }
  183. }
  184.  
  185. int main(int argc, char *argv[]) {
  186.     int *A = (int *) malloc(sizeof(int) * 8);
  187.     int *B = (int *) malloc(sizeof(int) * 7);
  188.     int *C = (int *) malloc(sizeof(int) * 6);
  189.     srand((unsigned int) time(0));
  190. }
Advertisement
Add Comment
Please, Sign In to add comment