Advertisement
eimkasp

JKM Testas 9 Var 1

Jan 21st, 2012
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4.  
  5. using namespace std;
  6. void nuskaitymas(int &n);
  7. int dRieksme(int &n);
  8. void Del(int n, int maxIndex);
  9. int A[100][100];
  10.  
  11.  
  12. int main() {
  13.     int n;
  14.     nuskaitymas(n);
  15.     dRieksme(n);
  16.     cin >> n;
  17.     return 0;
  18. }
  19.  
  20. void nuskaitymas(int &n) {
  21.     ifstream fd("Duomenys.txt");
  22.     ofstream fr("Rezultatai.txt");
  23.     fd >> n;
  24.     for(int i = 0; i < n;i++) {
  25.         for (int j = 0; j < n; j++) {
  26.             fd >> A[i][j];
  27.             fr << A[i][j] << " ";
  28.             cout << A[i][j] << " ";
  29.         }
  30.         cout << endl;
  31.         fr << endl;
  32.     }
  33.     fr << endl;
  34. }
  35.  
  36. int dRieksme(int &n) {
  37.     int max = INT_MIN;
  38.     int maxIndex = 0;
  39.     for(int i = 1; i < n;i++) {
  40.         for (int j = n-i; j < n; j++) {
  41.             if(A[i][j] > max) {
  42.                 max = A[i][j];
  43.                 maxIndex = i;
  44.             }
  45.         }
  46.     }
  47.     cout <<  "didziausias ksaicius " << max << " jo eilute yra " << maxIndex+1;
  48.     Del(n, maxIndex);
  49. return 0;
  50. }
  51.  
  52. void Del(int n, int maxIndex) {
  53.     ofstream fr("Rezultatai.txt", ios::app);
  54.     for(int i = 0; i < n;i++) {
  55.         for (int j = 0; j < n; j++) {
  56.             if (i != maxIndex) {
  57.             fr << A[i][j] << " ";
  58.             }
  59.         }
  60.     if (i != maxIndex) {
  61.             fr << endl;
  62.             }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement