smutnyjoe

Untitled

Dec 1st, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <fstream>
  4. #include <sstream>
  5.  
  6. using namespace std;
  7.  
  8. void wypisz(vector<int>& x){
  9.     for (int i : x)
  10.         cout << i << " ";
  11.  
  12.     cout << endl;
  13. }
  14.  
  15. void sortuj(vector<int> &a) {
  16.  
  17.     for (int i = 5; i >= 0; i--)
  18.         for (int j = 1; j <= i; j++ )
  19.             if (a[j-1] > a[j]) {
  20.                 int tmp = a[j];
  21.                 a[j] = a[j-1];
  22.                 a[j-1] = tmp;
  23.             }
  24.  
  25. }
  26.  
  27.  
  28.  
  29. int main() {
  30.     vector<int> a  = {7, 5, 1, 2, 3, 6};
  31.  
  32.     string linia;
  33.  
  34.     vector<vector<int>> obraz; //TODO pomyslec
  35.  
  36.     ifstream plik;
  37.     plik.open("../przyklad.txt");
  38.     if( !plik.good() ){
  39.         cout << "Nie można wczytać pliku" << endl;
  40.         return -1;
  41.     }
  42.  
  43.     while( getline(plik, linia) ) {
  44.         vector<int> v;
  45.         stringstream iss (linia);
  46.         int number;
  47.         while ( iss >> number )
  48.             v.push_back(number);
  49.         obraz.push_back(v);
  50.     }
  51.  
  52.  
  53.     cout << obraz[0][2] << endl;
  54.  
  55.     int najciemniejszy, najjasniejszy;
  56.     najjasniejszy = najciemniejszy = obraz[0][0];
  57.  
  58.     for(int i = 0; i < obraz.size(); i++ ){
  59.         for(int j = 0; j < obraz[i].size(); j++ ){
  60.             if( obraz[i][j] > najjasniejszy )
  61.                 najjasniejszy = obraz[i][j];
  62.  
  63.             if( obraz[i][j] < najciemniejszy )
  64.                 najciemniejszy = obraz[i][j];
  65.         }
  66.     }
  67.  
  68.     cout << "najjasniejszy: " << najjasniejszy << ", najciemniejszy; " << najciemniejszy << endl;
  69.  
  70.  
  71.  
  72.  
  73.     return 0;
  74. }
Add Comment
Please, Sign In to add comment