Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. main(){
  5.     int coba;
  6.     cin>>coba;
  7.     for (int i=0; i<coba; i++) {
  8.         int h,c,m,o,a;
  9.         cin>>h; cin>>c; cin>>m; cin>>o; cin>>a;
  10.         int mario=0, mons=0, obat=0;
  11.         // obat>damage monster
  12.         if (m<=a){
  13.             while ((o>0) && (h>0)) {
  14.                 o=o-c;
  15.                 mario++;
  16.                 h=h-a;
  17.                 mons++;
  18.                 if (h<=0) {
  19.                     cout<<"IMPOSSIBLE"<<endl;
  20.                 } else if (o<=0) {
  21.                     cout<<"POSSIBLE"<<endl;
  22.                     cout<<"SERANG "<<mario<<endl;
  23.                     cout<<"OBAT "<<obat<<endl;
  24.                 }
  25.             }
  26.         } else if (m>a) {
  27.             while (o>0){
  28.                 if (c>=o) {
  29.                     o=o-c;
  30.                     mario++;
  31.                 }
  32.                 else if (h>a) {
  33.                     o=o-c;
  34.                     mario++;
  35.                     if (o<=0) break;
  36.                     h=h-a;
  37.                     mons++;
  38.                 } else if (h<=a) {
  39.                     h=h+m;
  40.                     obat++;
  41.                     h=h-a;
  42.                     mons++;
  43.                 }
  44.                
  45.             }
  46.             cout<<"POSSIBLE"<<endl;
  47.             cout<<"SERANG "<<mario<<endl;
  48.             cout<<"OBAT "<<obat<<endl;
  49.         }
  50.     }
  51.    
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement