Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Koodinat
- {
- public:
- int x;
- int y;
- Koodinat(int x1, int y1)
- {
- x = x1;
- y = y1;
- }
- void increaseX()
- {
- x++;
- return;
- }
- void increaseY()
- {
- y++;
- return;
- }
- };
- int main()
- {
- int xAwal, yAwal, xTujuan, yTujuan;
- cin >> xAwal >> yAwal;
- cin >> xTujuan >> yTujuan;
- Koodinat lokasiAwal(xAwal, yAwal);
- Koodinat lokasiTujuan(xTujuan, yTujuan);
- Koodinat lokasiStep(lokasiAwal.x, lokasiAwal.y);
- int result = 0;
- bool isRun = true;
- while (isRun)
- {
- if (lokasiStep.x != lokasiTujuan.x)
- {
- lokasiStep.increaseX();
- result++;
- }
- if (lokasiStep.y != lokasiTujuan.y)
- {
- lokasiStep.increaseY();
- result++;
- }
- if (lokasiStep.x == lokasiTujuan.x && lokasiStep.y == lokasiTujuan.y)
- isRun = false;
- }
- cout << result;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement