Comparison of Android versions(strcmp的应用)

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 KTU84M

Sample Output

Case 1: > >

Case 2: = <

题目意思:这是一个安卓版本代码的比较,这里每组数据有两个代码代表不同的安卓版本分别得出版本的大小和日期的大小。版本代码中第一个字母代表着大版本,第二个字母代表分支版本,第三四五代表着日期,最后一个字母代表与日期相关的单个版本。题目要求是,先比较大版本,之后比较日期。如果分支版本相同,那么既要比较日期还要比较和日期相关的单个版本,如果分支版本不同,那么只需比较日期即可。

解题思路:前两天我还刚刚给我的大魅族升级到了安卓8.0,另一台华为也升级到了8.0,都彻底吃上了奥利奥。这个题对于不了解安卓版本的人来说看起来确实吃点力,实际上这个问题化简来看就可以看成:

1、比较两个字符串的第一个字母的大小;

2、如果两个字符串的第二个字母不同就比较接下来的三个字母的大小,如果第二个字母相同就比较剩余的四个字母!

 就是strcmp的应用

 1 #include<stdio.h>
 2 #include<string.h>
 3 int main()
 4 {
 5     int n,i,j,k,m;
 6     char s1[11],s2[11],a[11],b[11];
 7     scanf("%d",&n);
 8     getchar();
 9     for(i=1; i<=n; i++)
10     {
11         memset(a,0,sizeof(a));
12         memset(b,0,sizeof(b));
13         memset(s1,0,sizeof(s1));
14         memset(s2,0,sizeof(s2));
15         scanf("%s %s",s1,s2);
16         printf("Case %d: ",i);
17         if(s1[0]==s2[0])
18         {
19             printf("= ");
20         }
21         else if(s1[0]>s2[0])
22         {
23             printf("> ");
24         }
25         else if(s1[0]<s2[0])
26         {
27             printf("< ");
28         }
29         k=0;
30         m=0;
31         if(s1[1]==s2[1])
32         {
33             for(j=2; j<=5; j++)
34             {
35                 a[k++]=s1[j];
36                 b[m++]=s2[j];
37                 a[k]=‘\0‘;
38                 b[m]=‘\0‘;
39             }
40         }
41         else
42         {
43             for(j=2; j<=4; j++)
44             {
45                 a[k++]=s1[j];
46                 b[m++]=s2[j];
47                 a[k]=‘\0‘;
48                 b[m]=‘\0‘;
49             }
50         }
51         if(strcmp(a,b)==0)
52             printf("=");
53         else if(strcmp(a,b)<0)
54         {
55             printf("<");
56         }
57         else if(strcmp(a,b)>0)
58         {
59             printf(">");
60         }
61         printf("\n");
62     }
63     return 0;
64 }

原文地址:https://www.cnblogs.com/wkfvawl/p/9047756.html

时间: 2024-08-26 09:47:37

Comparison of Android versions(strcmp的应用)的相关文章

hdu 5099 Comparison of Android versions

Comparison of Android versions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1175    Accepted Submission(s): 472 Problem Description As an Android developer, itˇs really not easy to figure ou

HDU 5099 Comparison of Android versions(坑水题)

C - Comparison of Android versions HDU 5099 Time Limit: 1000 MS Memory Limit: 32768 KB 64-bit integer IO format: %I64d , %I64u Java class name: Main [Submit] [Status] Description As an Android developer, itˇs really not easy to figure out a newer ver

HDOJ 5099 Comparison of Android versions 坑题

现场赛的时候错了十四次. . ... Comparison of Android versions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 76    Accepted Submission(s): 60 Problem Description As an Android developer, itˇs really not e

模拟 HDOJ 5099 Comparison of Android versions

题目传送门 1 /* 2 题意:比较型号的大小 3 模拟:坑点在长度可能为5,此时设为'A' 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <iostream> 8 #include <cstring> 9 #include <cmath> 10 #include <string> 11 #include <vector> 12 #include &l

HDU 5099 Comparison of Android versions(字符串)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5099 Problem 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 id

hdu 5099 Comparison of Android versions 枚举题意

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5099 卡读题,实际上题目中表述的题意并不完整,所以要认真读并且加上一些现实的“常识” 关于枚举题意,感觉应该三个人分别看,然后讨论出最有可能的题意是什么 为了避免wa后心态的变化,在尽量保证不敲歪的前提下,在交之前就应该把所有可能的题意都想好,列出来,按可能性排序,再交 感觉只有做到了上面这些才能够wa后不慌 关于“第一个输出要判断前两个字母还是只判断第一个字母就好的问题” 注意到对于第一个字母,题

2014上海全国邀请赛 解题报告

Game with Pearls 贪心水题 http://blog.csdn.net/u012774187/article/details/40711559 Beam Cannon 线段树陈题 http://blog.csdn.net/u012774187/article/details/40712359 Seam Carving 简单DP http://blog.csdn.net/u012774187/article/details/40712899 Battle ships 二分图陈题 ht

The YubiKey -- COMPARISON OF VERSIONS

COMPARISON OF YUBIKEY VERSIONS   BASICSTANDARD & NANO BASICEDGE & EDGE-N PREMIUMNEO & NEO-N FIDO U2F SPECIALSECURITY KEY PRICE – SINGLE QUANTITY $25 $30 $50 $18   Buy Now Show Details Buy Now Show Details Buy Now Show Details Buy Now Show Deta

Android Hook框架adbi源码浅析(一)

adbi(The Android Dynamic Binary Instrumentation Toolkit)是一个Android平台通用hook框架,基于动态库注入与inline hook技术实现.该框架由两个主要模块构成,1.hijack负责将动态库注入到目标进程:2.libbase提供动态库本身,它实现了通用的hook功能. 而example则是一个使用adbi进行epoll_wait hook的demo. [email protected]PC:~/Android/adbi-maste