Description
Alice, Fzz’s daughter is a primary school student. Fzz loves his daughter so much that he drives to school every day exactly on time when the school day is over, which means when Fzz arrives school the school day is exactly over.
It is the 100th anniversary celebration of school today. After some interesting activities, the principal announce that school is over. Alice watches her watch, and she knows it is x minutes earlier compared to the time when the school day usually ends. She starts to go home.
After y minutes, she meets her Dad. Then she gets on the car. They go home happily by car.
When she arrives home, she finds it is z minutes earlier compared to the usual.
Alice is good at math. She wants to challenge her dad with some questions.
Now she gives two numbers of x, y, z and asks his father to calculate the third one.
For example, she says “dad, when y equals 30, and z equals to 20, what’s the x?”
Fzz gives the answer ‘40’ right after the question.
However it’s your turn. Can you calculate it?
Input
The input contains several cases.
First line contains an integer n, the number of test cases (n<=10000).
For each case, there are 2 integers and 1 character ‘?’. The first stands for x, the second stands for y, and the third stand for z.
Output
For each case, output in a single line with the answer to the ‘?’. It is guaranteed all the number will be positive integer no more than 1000000 (both Input & output).
Sample Input
3
? 30 20
40 ? 20
40 30 ?
Sample Output
40
30
20
Alice在放学后走了y分钟,遇到Fzz,然后提前了z分钟回到家。那也就是说从他们遇到的地方到学校是z/2分钟车程。(因为Fzz每天都在放学的那一刻刚好到达学校,而他们少走的路程就是2倍的相遇点到学校。)所以我们就有:x = y + z / 2。给定其2,求第三。
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
char x[30],y[30],z[30];
int a,b,c,m,n;
scanf("%s%s%s",x,y,z);
if(x[0]=='?') {
m=atoi(y);n=atoi(z);
a=n/2+m;
printf("%d\n",a);
}
if(y[0]=='?') {
m=atoi(x);n=atoi(z);
b=m-n/2;
printf("%d\n",b);
}
if(z[0]=='?') {
m=atoi(x);n=atoi(y);
c=(m-n)*2;
printf("%d\n",c);
}
}
return 0;
}