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): 1178    Accepted Submission(s): 474


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 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: = <
 

Source

题目链接。


两次比较: 
1、比较发布版本号的大小(字母顺序)。
2、比较剩余代码的大小: 
①如果分支代码(第2个字母)不同,则只需比较日期代码(第3、4、5个字母)。 
②如果分支代码相同,则需比较剩余的四个字母(第3、4、5、6)。


个体版本,也就是最后一个字母,如果为A,通常为了简洁而省略不写。 


#include <cstdio>
#include <cstring>
const int maxn = 10;
char bn1[maxn],bn2[maxn];
char one,two;
void cmp1()
{
	if(bn1[0]>bn2[0]) one = '>';
	else if(bn1[0]==bn2[0]) one = '=';
	else one = '<';
}
void cmp2()
{
	int i;
	for(i=2;i<=4;++i)				//先直接比较日期代码 
		if(bn1[i]!=bn2[i])
		{
			if(bn1[i]>bn2[i]) two = '>';
			else two = '<';
			return ;
		}
	two = '=';
	if(bn1[1]==bn2[1])				//如果日期代码相同,则判断分支代码是否相同,相同则比较最后一个字母 
	{
		if(bn1[5]>bn2[5])  two= '>';
		else if(bn1[5]==bn2[5]) two = '=';
		else two = '<';
	}
}
int main()
{
	int n,k=1,flag;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%s%s",bn1,bn2);
		if(strlen(bn1)<6) bn1[5]='A';
		if(strlen(bn2)<6) bn2[5]='A';
		cmp1();
		cmp2();
		printf("Case %d: %c %c\n",k++,one,two);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
字符串哈希滑动窗口是一种用于处理字符串的算法。它主要用于在给定的字符串中找到满足特定条件的子串。 在字符串哈希滑动窗口算法中,我们首先计算原始字符串的哈希值。然后,我们使用一个滑动窗口来遍历字符串,每次滑动一个固定长度的窗口。我们可以通过比较每个窗口内的子串的哈希值来判断是否满足条件。 具体而言,我们可以使用BKDRHash等哈希函数来计算字符串的哈希值。然后,我们枚举每个可能的起点,并使用滑动窗口来计算窗口内的子串的哈希值。通过比较窗口内的子串的哈希值,我们可以判断是否满足条件。 对于滑动窗口的移动,如果窗口内的子串满足条件,我们可以继续将窗口往右移动一个固定的长度。如果窗口内的子串不满足条件,我们将窗口的右边界移到最右端,并依次比较新窗口内的子串的哈希值。 综上所述,字符串哈希滑动窗口算法是通过计算字符串的哈希值,并使用滑动窗口来遍历字符串,以找到满足特定条件的子串。这个算法可以高效地处理字符串,并且能够应用于各种字符串相关的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [String (字符串哈希+滑动窗口)](https://blog.csdn.net/weixin_43872264/article/details/107571742)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [【字符串hash+滑动窗口】String HDU - 4821](https://blog.csdn.net/qq_45599865/article/details/111143633)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值