Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <fstream>
  5. #include <iostream>
  6. #include <string>
  7. using namespace std;
  8. typedef struct{
  9.     unsigned int id;
  10.     float cas;
  11. }Tcasy;
  12.  
  13. int main(int argc, char* argv[])
  14. {
  15.     string N;
  16.     int i,j,k;
  17.     N = argv[4];
  18.     int NE = atoi(N.c_str());
  19.    
  20.     FILE *f1,*f2;
  21.     Tcasy *sou1,*sou2;
  22.     if(fopen_s(&f1,argv[1],"rb") != 0)
  23.     {
  24.         cout << "Nenacteno 1"<<endl;
  25.         return -1;
  26.     }
  27.     fseek(f1,0,SEEK_END);
  28.     long vel = ftell(f1);
  29.    
  30.     fseek(f1,0,SEEK_SET);
  31.     sou1 = (Tcasy*)malloc(vel);
  32.     int poc = vel / sizeof(Tcasy);
  33.    
  34.     fread(sou1,sizeof(Tcasy),poc,f1);
  35.    
  36.     if(fopen_s(&f2,argv[2],"rb")!= 0)
  37.     {
  38.         cout << "Nenacteno 2"<<endl;
  39.         return -2;
  40.     }
  41.     fseek(f2,0,SEEK_END);
  42.     long vel2 = ftell(f2);
  43.    
  44.     fseek(f2,0,SEEK_SET);
  45.     sou2 = (Tcasy*)malloc(vel2);
  46.     int poc2 = vel2 / sizeof(Tcasy);
  47.    
  48.     fread(sou2,sizeof(Tcasy),poc2,f2);
  49.    
  50.     k = poc-1;
  51.     j = poc2-1;
  52.     Tcasy *vys;
  53.     vys =(Tcasy*) malloc(sizeof(Tcasy) * NE);
  54.  
  55.     ofstream vystup(argv[3]);
  56.     for(i = 0; i < NE; i++)
  57.     {
  58.         if(sou1[k].cas > sou2[j].cas)
  59.         {
  60.             vys[i] = sou1[k];
  61.             k--;
  62.         }
  63.         else{
  64.             vys[i] = sou2[j];
  65.             j--;
  66.         }
  67.     }
  68.     for(i = NE-1; i >= 0; i--)
  69.     {
  70.         vystup << vys[i].id << " " <<vys[i].cas<<endl;
  71.     }
  72.     fclose(f1);
  73.     fclose(f2);
  74.     free(sou1);
  75.     free(sou2);
  76.     free(vys);
  77.     vystup.close();
  78.  
  79.     system("pause");
  80.     return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement