DEV Community

thequvonc
thequvonc

Posted on

Yandex taxi

deyarli kopchilik 'Yandex taxi'ilovasidan foydalanadi
lekin kopincha bizda qaytim muammosi uchraydi
bugun biz shu masalani xal etamiz!

#include <iostream>
using namespace std;
int main() {

  int son;
  cin >> son;

  int qoldiq = son % 1000;

if (qoldiq < 500){
  cout << son - qoldiq;
  }
else{
  cout << son - qoldiq + 1000;
  }


  return 0;
}


Enter fullscreen mode Exit fullscreen mode

bunda int son yozib uni oqib olamiz
keyin esa aniq sonni 1000 sum deb belgilagandan song

keyin bizga qaytim degan ozgaruvchi kerak boladi
keyin sonni bolamiz 1000 ga oshanda esa bu bizning qaytimimizni qaniqlab beradi

if (qoldiq < 500){
  cout << son - qoldiq;
  }

Enter fullscreen mode Exit fullscreen mode

keyin aniqlab olamiz if ya'ni agar qaytimimiz 500 summdan kichik
bolsa uni qaytimdagi sonini anig'ini chiqarishimiz zarur

keyin cout << son deb uni 1000 sumga kopaytirib olamiz da uni javobini chiqaramiz.

@dawroun

Top comments (0)