where is my wrong
ths
Code: Select all
my code is below
// uva_10424.cpp
//
#include <iostream>
#include <string.h>
#include<iomanip>
#include<stdio.h>
#define MAX_SIZE 512
using namespace std;
int caluated_str_value(char *str)
{
/*
A=65
Z=90
a=97
z=122
0=48
9=57*/
int sum=0;
char str_array[MAX_SIZE]={NULL};
strcpy(str_array,str);
do
{ sum=0;
for(int i=0;i<strlen(str_array);i++)
{
int char_value=str_array[i];
if(char_value>=48 &&char_value<=57)
{
sum=sum+int(str_array[i]-48);
}
if(char_value>=65 &&char_value<=90)
{
sum=sum+int(str_array[i]-64);
}
if(char_value>=97 &&char_value<=122)
{
sum=sum+int(str_array[i]-96);
}
}
char sum_array[MAX_SIZE]={NULL};
sprintf(sum_array,"%d",sum);
strcpy(str_array,sum_array);
}while(strlen(str_array)!=1);
return sum;
}
int main()
{
char a_str[MAX_SIZE]={NULL},b_str[MAX_SIZE]={NULL};
float a_val=0,b_val=0;
while(cin>>a_str>>b_str)
{
for(int i=0;i<=1;i++)
{
if(i==0)
a_val=caluated_str_value(a_str);
else
b_val=caluated_str_value(b_str);
}
if(a_val>b_val)
{
float ans=b_val/a_val*100;
cout<<fixed<<setprecision(2)<<ans<<" %"<<endl;
}
else
{
float ans=a_val/b_val*100;
cout<<fixed<<setprecision(2)<<ans<<" %"<<endl;
}
}
return 0;
}