59 237375 743200000 8496942500000 8000000Sample Output11628300612Deficit題意:每五個月報一次表,這個表一定是虧得,這五個月為1-5,2-6,3-7.......然后你輸入是s和d,s代表的是每月盈利,d代表每月虧損,問你每年最大能賺多少錢。分6種情況:(x為這五個月中盈利月的個數)1.當x為1時ssssd,ssssd,ss。x為2sssdd,sssdd,ss。x為3ssddd,ssddd,ss。x為4sdddd,sdddd,sd。x為5ddddd,ddddd,dd這時一定虧損,so代碼如下:#include <iostream>using namespace std;int main(){ int s,d; int res; while(cin>>s && cin>>d) { if(d>4*s)res=10*s-2*d; else if(2*d>3*s)res=8*s-4*d; else if(3*d>2*s)res=6*(s-d); else if(4*d>s)res=3*(s-3*d); else res=-1; if(res<0)cout<<"Deficit"<<endl; else cout<<res<<endl; } return 0;}
新聞熱點
疑難解答