Problem Type : String
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int calculate(int a)
{
int n=0,m=0,i;
if(a<=9)
return a;
else if(a>9)
{
for(i=0;; i++)
{
n+=(a%10);
m=a/10;
a=m;
if(a<=9)
{
n=n+a;
break;
}
}
return calculate(n);
}
}
int love(char str[])
{
int i,a,j,sum=0, count=0,b,n=0,l=0;
l=strlen(str);
for(i=0; i<l; i++)
{
if(str[i]>=65 && str[i]<=90 || str[i]>=97 && str[i]<=122)
{
if(str[i]=='a'|| str[i]=='A')
count=1;
else if(str[i]=='b'|| str[i]=='B')
count=2;
else if(str[i]=='c'|| str[i]=='C')
count=3;
else if(str[i]=='d'|| str[i]=='D')
count=4;
else if(str[i]=='e'|| str[i]=='E')
count=5;
else if(str[i]=='f'|| str[i]=='F')
count=6;
else if(str[i]=='g'|| str[i]=='G')
count=7;
else if(str[i]=='h'|| str[i]=='H')
count=8;
else if(str[i]=='i'|| str[i]=='I')
count=9;
else if(str[i]=='j'|| str[i]=='J')
count=10;
else if(str[i]=='k'|| str[i]=='K')
count=11;
else if(str[i]=='l'|| str[i]=='L')
count=12;
else if(str[i]=='m'|| str[i]=='M')
count=13;
else if(str[i]=='n'|| str[i]=='N')
count=14;
else if(str[i]=='o'|| str[i]=='O')
count=15;
else if(str[i]=='p'|| str[i]=='P')
count=16;
else if(str[i]=='q'|| str[i]=='Q')
count=17;
else if(str[i]=='r'|| str[i]=='R')
count=18;
else if(str[i]=='s'|| str[i]=='S')
count=19;
else if(str[i]=='t'|| str[i]=='T')
count=20;
else if(str[i]=='u'|| str[i]=='U')
count=21;
else if(str[i]=='v'|| str[i]=='V')
count=22;
else if(str[i]=='w'|| str[i]=='W')
count=23;
else if(str[i]=='x'|| str[i]=='X')
count=24;
else if(str[i]=='y'|| str[i]=='Y')
count=25;
else if(str[i]=='z'|| str[i]=='Z')
count=26;
sum=sum+count;
}
else
continue;
}
if(sum>9)
{
n=calculate(sum);
return n;
}
else
return sum;
}
int main()
{
int m,f,n;
double sum,o,p;
char ch[1000],des[1000];
while(gets(ch))
{
gets(des);
m=love(ch);
o=((double)(m));
f=love(des);
p=((double)(f));
if(o>p)
{
sum=((p*100)/o);
}
else
{
sum=((o*100)/p);
}
printf("%.2lf %\n",sum);
}
return 0;
}
/*This code shown you love parcentage between two parson
Sample input :
saima
shanto
Pakistan
India
USA
USSR
Sample output :
71.43 %
100.00 %
100.00 %
*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int calculate(int a)
{
int n=0,m=0,i;
if(a<=9)
return a;
else if(a>9)
{
for(i=0;; i++)
{
n+=(a%10);
m=a/10;
a=m;
if(a<=9)
{
n=n+a;
break;
}
}
return calculate(n);
}
}
int love(char str[])
{
int i,a,j,sum=0, count=0,b,n=0,l=0;
l=strlen(str);
for(i=0; i<l; i++)
{
if(str[i]>=65 && str[i]<=90 || str[i]>=97 && str[i]<=122)
{
if(str[i]=='a'|| str[i]=='A')
count=1;
else if(str[i]=='b'|| str[i]=='B')
count=2;
else if(str[i]=='c'|| str[i]=='C')
count=3;
else if(str[i]=='d'|| str[i]=='D')
count=4;
else if(str[i]=='e'|| str[i]=='E')
count=5;
else if(str[i]=='f'|| str[i]=='F')
count=6;
else if(str[i]=='g'|| str[i]=='G')
count=7;
else if(str[i]=='h'|| str[i]=='H')
count=8;
else if(str[i]=='i'|| str[i]=='I')
count=9;
else if(str[i]=='j'|| str[i]=='J')
count=10;
else if(str[i]=='k'|| str[i]=='K')
count=11;
else if(str[i]=='l'|| str[i]=='L')
count=12;
else if(str[i]=='m'|| str[i]=='M')
count=13;
else if(str[i]=='n'|| str[i]=='N')
count=14;
else if(str[i]=='o'|| str[i]=='O')
count=15;
else if(str[i]=='p'|| str[i]=='P')
count=16;
else if(str[i]=='q'|| str[i]=='Q')
count=17;
else if(str[i]=='r'|| str[i]=='R')
count=18;
else if(str[i]=='s'|| str[i]=='S')
count=19;
else if(str[i]=='t'|| str[i]=='T')
count=20;
else if(str[i]=='u'|| str[i]=='U')
count=21;
else if(str[i]=='v'|| str[i]=='V')
count=22;
else if(str[i]=='w'|| str[i]=='W')
count=23;
else if(str[i]=='x'|| str[i]=='X')
count=24;
else if(str[i]=='y'|| str[i]=='Y')
count=25;
else if(str[i]=='z'|| str[i]=='Z')
count=26;
sum=sum+count;
}
else
continue;
}
if(sum>9)
{
n=calculate(sum);
return n;
}
else
return sum;
}
int main()
{
int m,f,n;
double sum,o,p;
char ch[1000],des[1000];
while(gets(ch))
{
gets(des);
m=love(ch);
o=((double)(m));
f=love(des);
p=((double)(f));
if(o>p)
{
sum=((p*100)/o);
}
else
{
sum=((o*100)/p);
}
printf("%.2lf %\n",sum);
}
return 0;
}
/*This code shown you love parcentage between two parson
Sample input :
saima
shanto
Pakistan
India
USA
USSR
Sample output :
71.43 %
100.00 %
100.00 %
*/
No comments:
Post a Comment