Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int maxsorok=1000;
  6. int beolvas_egesz();
  7. void beolvas_matrix(const int sorok,const int oszlopok, int tomb[][maxsorok]);
  8. int feladat(const int sorok,const int oszlopok,int tomb[][maxsorok]);
  9.  
  10.  
  11. int main()
  12. {
  13.     setlocale(LC_ALL,"hun");
  14.  
  15.     int napok;
  16.     int orok;
  17.  
  18.     napok = beolvas_egesz();
  19.     orok = beolvas_egesz();
  20.  
  21.     int asd[napok][maxsorok];
  22.  
  23.     beolvas_matrix(napok,orok,asd);
  24.  
  25.     int megoldas;
  26.     megoldas=feladat(napok,orok,asd);
  27.  
  28.     cout << megoldas;
  29.  
  30.      for (int j=0;j<napok;j++) {
  31.         for (int k=0;k<orok;k++) {
  32.             cout << asd[j][k] << " ";
  33.         }
  34.         cout << endl;
  35.     }
  36.     return 0;
  37. }
  38.  
  39.  
  40. int beolvas_egesz() {
  41.     int szam;
  42.     cin >> szam;
  43.     return szam;
  44. }
  45.  
  46. void beolvas_matrix(const int sorok,const int oszlopok, int tomb[][maxsorok]) {
  47.     int start[oszlopok];
  48.     int veg[oszlopok];
  49.  
  50.     for (int i=0;i<sorok;i++) {
  51.         cin >> start[i] >> veg[i];
  52.         for (int j=0;j<oszlopok;j++) {
  53.             if (j>= start[i]-1 && j<veg[i]) {
  54.                 tomb[i][j] = 1;
  55.             }
  56.             else {
  57.                 tomb[i][j] = 0;
  58.             }
  59.         }
  60.     }
  61. }
  62.  
  63. int feladat(const int sorok,const int oszlopok,int tomb[][maxsorok]) {
  64.  
  65.     bool empty;
  66.     int i;
  67.     for (i=0;i<oszlopok;i++) {
  68.  
  69.         empty=true;
  70.         for (int j=0;j<sorok && empty;j++) {
  71.             if (tomb[j][i] == 1) {
  72.  
  73.                 empty = false;
  74.             }
  75.         }
  76.         if(empty) {
  77.             return i+1;
  78.         }
  79.     }
  80.     return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement