Description
As an Android developer, itˇs really not easy to figure out a newer version of two kernels, because Android is updated so frequently and has many branches. Fortunately, Google identifies individual builds with a short build code, e.g. FRF85B.
The first letter is the code name of the release family, e.g. F is Froyo. The code names are ordered alphabetically. The latest code name is K (KitKat).
The second letter is a branch code that allows Google to identify the exact code branch that the build was made from, and R is by convention the primary release branch.
The next letter and two digits are a date code. The letter counts quarters, with A being Q1 2009. Therefore, F is Q2 2010. The two digits count days within the quarter, so F85 is June 24 2010.
Finally, the last letter identifies individual versions related to the same date code, sequentially starting with A; A is actually implicit and usually omitted for brevity.
Please develop a program to compare two Android build numbers.
Input
The first line is an integer n (1 <= n <= 2000), which indicates how many test cases need to process.
Each test case consists of a single line containing two build numbers, separated by a space character.
Output
For each test case, output a single line starting with ¨Case #: 〃 (# means the number of the test case). Then, output the result of release comparison as follows:
● Print "<" if the release of the first build number is lower than the second one;
● Print "=" if the release of the first build number is same as he second one;
● Print ">" if the release of the first build number is higher than the second one.
Continue to output the result of date comparison as follows:
● Print "<" if the date of the first build number is lower than the second one;
● Print "=" if the date of the first build number is same as he second one;
● Print ">" if the date of the first build number is higher than the second one.
If two builds are not in the same code branch, just compare the date code; if they are in the same code branch, compare the date code together with the individual version.
Sample Input
2 FRF85B EPF21B KTU84L KTU84MSample Output
Case 1: > > Case 2: = <
题解:读懂题意,主要是第二个字母的判断。
代码如下:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define mem(a,b) memset(a,b,sizeof(a))
#define For(a,b) for(int a=0;a<b;a++)
using namespace std;
const int maxn = 1e3+500;
const int INF = 0x3f3f3f3f;
const int inf = 0x3f;
typedef long long ll;
const ll mod = 1e9+7;
char c[2][maxn];
int juge(char a,char b) {
int flag = 0;
if(a>b)
return 1;
if(a<b)
return -1;
return 0;
}
int main() {
int t;
int flag1,flag2;
cin >> t;
For(q,t) {
cin >>c[0]>>c[1];
flag1 = juge(c[0][0],c[1][0]);
flag2 = juge(c[0][1],c[1][1]);
if(flag2 != 0) {
flag2 = juge(c[0][2],c[1][2]);
if(flag2 == 0)
flag2 = juge(c[0][3],c[1][3]);
if(flag2 == 0)
flag2 = juge(c[0][4],c[1][4]);
}
else{
if(flag2 == 0)
flag2 = juge(c[0][2],c[1][2]);
if(flag2 == 0)
flag2 = juge(c[0][3],c[1][3]);
if(flag2 == 0)
flag2 = juge(c[0][4],c[1][4]);
if(flag2 == 0)
flag2 = juge(c[0][5],c[1][5]);
}
cout <<"Case "<<q+1<<": ";
if(flag1 == 0)
cout <<"= ";
else if(flag1 < 0)
cout <<"< ";
else
cout <<"> ";
if(flag2 == 0)
cout <<"=";
else if(flag2 <0)
cout <<"<";
else
cout <<">";
cout << endl;
}
return 0;
}