题解 AT2447 【電子レンジ (Microwave) 】

· · 题解

这道题只要分四种情况讨论即可。

上菜:

#include<bits/stdc++.h>
using namespace std;
inline int read()
{   int x=0;
    bool f=0;
    char c=getchar();
    while(!isdigit(c))f|=(c=='-'),c=getchar();
    while(isdigit(c))x=x*10+(c&15),c=getchar();
    return f?-x:x;
}
int main()
{   int a=read(),b=read(),c=read(),d=read(),e=read(),ans;
    if(a<0)//四种情况。
    {   if(b<=0)ans=(b-a)*c;
        else ans=abs(a)*c+d+b*e;
    }
    else 
    {   if(a==0)ans=d+b*e;
        else ans=(b-a)*e;
    }
    cout<<ans<<endl;
    return 0;
}