1856. Anagrammatic Distance

一次性过了,较简单~

Two words are said to be anagrams of each other if the letters from one word can be rearranged to form the other word. For example, occurs is an anagram of succor; however, dear is not an anagram of dared (because the d appears twice in dared, but only once in dear). The most famous anagram pair (in English) is dog and god.

The anagrammatic distance between any two words is the minimum number of letters which must be removed so that the remaining portions of the two words become anagrams. For example, given the words sleep and leap, we need to remove a minimum of three letters --- two from sleep and one from leap --- before what's left are anagrams of each other (in each case, lep). With words such as dog and cat, where the two have absolutely no letters in common, the anagrammatic distance is an extreme (explicitly 6) since all the letters need to be removed. (Here, a word is always an anagram of itself.)

You must write a program to calculate the anagrammatic distance between any two given words.

Input

The first line of the input will contain a positive integer value N (less than 60,000) indicating the number of cases. Each case will consist of two words, possibly empty, each given on a single line (for a total of 2N additional lines).

Although they may have zero length, the words are simple --- the letter are all lowercase and are taken from the usual twenty-six letter English alphabet (abcdefghijklmnopqrstuvwxyz). The longest word is pneumonoultramicroscopicsilicovolcanoconiosis.

Output

The output should consist of the case number and the anagrammatic distance, formatted as shown. There are two spaces after the colon.

Sample Input

4
crocus
succor
dares
seared
empty

smell
lemon

Sample Output

Case #1:  0
Case #2:  1
Case #3:  5
Case #4:  4
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<cstring>
using namespace std;
int main(){
	int n,i,l1,l2,m,sum;
	char a[100],b[100];
	cin>>n;
	getchar();
	for(i=1;i<=n;i++){
		gets(a);
		gets(b);
		l1=strlen(a);
		l2=strlen(b);
		sort(a,a+l1);
		sort(b,b+l2);
		m=0;
		sum=l1+l2;
		for(int j=0;j<l1;j++)
			for(int k=m;k<l2;k++){
			//	cout<<a[j]<<a[k]<<endl;
				if(a[j]==b[k]){
					sum=sum-2;
					m=k+1;
					break;
				}
			}
			cout<<"Case #"<<i<<":  "<<sum<<endl;
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值