AtCoder - abc092_a Traveling Budget
Problem Description:
You planned a trip using trains and buses. The train fare will be Ayen (the currency of Japan) if you buy ordinary tickets along the way, and Byen if you buy an unlimited ticket. Similarly, the bus fare will be Cyen if you buy ordinary tickets along the way, and Dyen if you buy an unlimited ticket.Find the minimum total fare when the optimal choices are made for trains and buses.
1<=A B C D<=1000;
Input
Input is given from Standard Input in the following format:
A
B
C
D
Output
Print the minimum total fare.
Sample Input 1
600
300
220
420
Sample Output 1
520
The train fare will be 600 yen if you buy ordinary tickets, and 300yen if you buy an unlimited ticket. Thus, the optimal choice for trains is to buy an unlimited ticket for 300 yen. On the other hand, the optimal choice for buses is to buy ordinary tickets for 220 yen.
Therefore, the minimum total fare is 300+220=520yen.
Sample Input 2
555
555
400
200
Sample Output 2
755
Sample Input 3
549
817
715
603
Sample Output 3
1152
思路:选择两种车票的最低价 然后相加;
代码:
#include <iostream>
using namespace std;
int main()
{
int a,b,c,d,e,f;
while(cin>>a>>b>>c>>d)
{
{
if(a>b)
f=b;
else
f=a;
}
{
if(c>d)
e=d;
else
e=c;
}
cout<<e+f<<endl;
}
}
*欢迎各位网友指点~~~~*