JosepRivaille

X58169: Posicions d'un màxim a dues seqüències

Apr 9th, 2015
1,165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. void infoSequencia(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.         infoSequencia(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