10424 - Love Calculator

Problem F
Love Calculator 
Input:
 standard input
Output: standard output
Time Limit: 2 seconds

Background

One day I asked Saima that how much she loves me. Her answer was "71.43 %". I was surprised as well as shocked by her answer. I could not understand why she didn't tell 100% and why she told a particular and peculiar fraction like 71.43. Looking at my surprised, shocked and nervous face she burst out laughing and told that she loves me more than any thing in this universe and it was nothing but a silly and funny love calculation. Then she described me the calculation. In this problem you will have to write a program so that any one can calculate love between any two persons very quickly (of course a very silly game).    

 

Rules

You will be given two names. These two names can have white space or some other non-alphabetical characters like $ @ & % etc. But only the alphabets from a to z or A to Z will participate in love calculation. Each alphabet has a particular value. The values are from 1 to 26 in ascending order of the alphabets. Its like this, a = 1, b = 2, c = 3........ z = 26. Both upper case and lower case holds the same values. Then make the sum of these numbers until it comes in one digit.[ For example, consider a name 'bcz'. Here, b = 2, c = 3 & z = 26. So, the sum is (2+3+26) = 31 = (3+1) = 4.] Then the ratio of these two numbers in percentage will be the result.

 

Remember : Result can not be more than 100 % . Take the ratio carefully to avoid this problem.

 

Input

Your input will be two names. Each name holds not more than 25 characters. End of file will indicate the end of input.

 

Output

For each pair of names your program will have to calculate the love between those two persons and give the result as output. In result two digits to be displayed after the decimal point. All the results must be in new lines.

  

Sample input

saima

shanto

Pakistan

India

USA

USSR

Sample output

71.43 %

100.00 %

100.00 %

#include<stdio.h>
#include<string.h>
char a[30],b[30];
int main()
{
	while(gets(a)&&gets(b))
	{
		int x=0,y=0,i;
		for(i=0;i<strlen(a);i++)
			if(a[i]<='z'&&a[i]>='a')
				x+=a[i]-'a'+1;
			else if(a[i]<='Z'&&a[i]>='A')
				x+=a[i]-'A'+1;
		for(i=0;i<strlen(b);i++)
			if(b[i]<='z'&&b[i]>='a')
				y+=b[i]-'a'+1;
			else if(b[i]<='Z'&&b[i]>='A')
				y+=b[i]-'A'+1;
		if(x%9==0) x=9;else x=x%9;
		if(y%9==0) y=9;else y=y%9;
		double ans;
		if(x<y)
			ans=(double)x/(double)y;
		else
			ans=(double)y/(double)x;
		printf("%.2f %%\n",ans*100);
	}
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值