简单题。但代码可以写得简洁如:http://poj.org/showmessage?message_id=346379
也可以写得像我这样繁琐。
thestoryofsnow | 1663 | Accepted | 164K | 16MS | C++ | 883B |
/*
ID: thestor1
LANG: C++
TASK: poj1663
*/
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <limits>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cassert>
using namespace std;
int main()
{
int T;
scanf("%d", &T);
int x, y;
bool isAbove, isLower;
for (int t = 0; t < T; ++t)
{
scanf("%d%d", &x, &y);
isAbove = (y == x);
isLower = (y == x - 2);
if ((!isAbove && !isLower) || x < 0 || y < 0)
{
printf("No Number\n");
continue;
}
if (isAbove)
{
if (x % 2 == 0)
{
printf("%d\n", x * 2);
}
else
{
printf("%d\n", x * 2 - 1);
}
}
else
{
if (x % 2 == 0)
{
printf("%d\n", x * 2 - 2);
}
else
{
printf("%d\n", x * 2 - 3);
}
}
}
return 0;
}