多个if else C ++ [英] Multiple if else C++
本文介绍了多个if else C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
This is my online test, it is talking about verdict in competitive programming. I am asking about how to get multiple outputs with the same "if-else" statement and how to turn the "T" into number of cases, so that if I enter 4 number of cases, it will allow me to give 4 different inputs and having also 4 outputs?
Input
The first row consist of number T (1≤ T ≤ 100) which shows how many are the test cases. For every case, it consist of 6 type of numbers, Wj,Wp,Mj,Mp,Jj,Jp ( 1 ≤ Wj,Wp,Mj,Mp,Jj,Jp ≤ 100) with each shows time limit, process time needed, memory limit, memory used, judge answer, participant answer.
Output
For every test case,"Case #X: Y", where X shows the case number and Y are as following:
1. If the process time are bigger than the time limit, print "TIME LIMIT EXCEEDED / TIMELIMIT".
2. Else if memory used are bigger than memory limit, print "MEMORY LIMIT EXCEEDED".
3. Else if judge answer ≠ participants answer, print "WRONG-ANSWER".
4. Else print "ACCEPTED / CORRECT".
Sample Input:
4
10 5 10 10 1 1
5 10 5 10 0 1
10 5 5 10 1 1
10 10 10 10 1 2
Sample Output:
Case #1: ACCEPTED / CORRECT
Case #2: TIME LIMIT EXCEEDED / TIMELIMIT
Case #3: MEMORY LIMIT EXCEEDED
Case #4: WRONG-ANSWER
我尝试过:
What I have tried:
#include <stdio.h>
int main (){
int T,Wj,Wp,Mj,Mp,Jj,Jp;
scanf ("%d",&T);
scanf ("%d %d %d %d %d %d",&Wj,&Wp,&Mj,&Mp,&Jj,&Jp);
if (Wp > Wj) {
printf ("TIME LIMIT EXCEEDED / TIMELIMIT");
}
else if (Mp > Mj) {
printf ("MEMORY LIMIT EXCEEDED");
}
else if (Jp!=Jj) {
printf ("WRONG-ANSWER");
}
else {
printf ("ACCEPTED / CORRECT");
}
return 0;
}
推荐答案
while(T-- > 0) // get values of Wp, Wj .. 'T' times
{
scanf("%d %d .. ", &Wj, &Wp ...); // get values
// multiple evaluation
printf("%s::%s::%s::%s\n", Wp > Wj ? "TIME LIMIT" : " ", <other tests & corresponding output>, !(Wp > Wj || ... || Jp != Jj) ? "CORRECT " : " ");
}
我不确定我是否完全了解您的要求,但我已尽力回复。
I am not sure I have understood your requirement exactly but have tried to reply as best as I could interpret.
这篇关于多个if else C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文