csansoon

P6.21 X58169 Positions of a maximum within two sequences

Nov 8th, 2018
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. void infoSequence(int& max, int& lpos) {
  6.         if (lpos > max) max = lpos;
  7. }
  8.  
  9. int main() {
  10.         int n1, lpos, count = 0, pos, max = 0;
  11.         while (cin >> n1 && n1 != 0) {
  12.                 lpos = n1;
  13.                 infoSequence(max, lpos);
  14.                 ++count;
  15.                 if (max == lpos) pos = count;
  16.         }
  17.         cout << max << ' ' << pos << ' ';
  18.         int n2, pos2 = 1;
  19.         while (cin >> n2 && n2 != max && n2 != 0) {
  20.                 ++pos2;
  21.         }
  22.         if (n2 == max) cout << pos2 << endl;
  23.         else cout << '-' << endl;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment