STANAANDREY

bac 4/220/2022 3

Apr 20th, 2022 (edited)
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. ifstream fin("numere.in");
  5.  
  6. int main() {
  7.     int n, x1, x2, k = 0;
  8.     fin >> n >> x1;
  9.     k = n - x1;
  10.     while ((fin >> x2)) {
  11.         if (x1 != x2) {
  12.             k += (x1 - x2) - 1;
  13.         }
  14.         x1 = x2;
  15.     }
  16.     k += x2 - 1;
  17.     cout << k << endl;
  18.     return 0;
  19. }
  20.  
Add Comment
Please, Sign In to add comment