 # Test cases for december lunchtime

Simply put…You can’t…

Yes you can’t…you must figure out the edge cases yourself

You have to become admin of lunchtime for that to happen.

can anyone tell me what this statement means…
if( ( str[i] - ‘A’ ) > 25 …this str[i] -‘A’ ???

‘A’ means the ascii value of “A”. When we subtract it from character, it gives it’s relative position. It basically maps the characters to numbers.

Eg. s = “ABCDEF”
s - ‘A’ = 0
s - ‘A’ = ‘C’ - ‘A’ = 2
s - ‘A’ = 5

thank you so much for the reply and for such an easy explanation…thanks a lot !!!

1 Like

can you tell me why the condition is greater than 25…

the code goes like this…
if((str[i]-‘A’)>25)
{

``````		cout<<alpha[str[i]-'a'];
}
else
{
putchar(toupper(alpha[str[i]-'A']));
}``````

give the value of str

the code goes like this…Tourist translation
#include<bits/stdc++.h>
using namespace std;
int main()
{
string alpha,str;
long T,t;
cin>>T;
cin>>alpha;
while(T–)
{
cin>>str;
for (long i = 0; i < str.length(); ++i)
{
if(str[i]==’.’ || str[i]==’,’ || str[i]==’!’ || str[i]==’?’)
{
cout<<str[i];
}
else if(str[i]==’_’)
{
cout<<" ";
}
else
{
if((str[i]-‘A’)>25)
{

``````		cout<<alpha[str[i]-'a'];
}
else
{
putchar(toupper(alpha[str[i]-'A']));
}

}
}
cout<<endl;
}
``````

}

the last “if” condition is for checking whether the given character lies in the range “A-Z”,“65-91” or not.If this condition is false then it simply means that the character in consideration is not upper case so we first have to convert it into upper-case by using “toupper” function and then print it.moreover you can just google search for ASCII table and see what character represent what value.

but…as you said range of “A-Z” is “65-91”,and for small “a,b,c…” its “97-122”…then why " 25"…it comes nowhere in between …

Ok. Good consider few examples as given below.
1.str[i]=A.
resulting in ASCII value of 65.
So, str[i]-‘A’ will result in 0 as 65-65=0.
And, 0<25 which makes the if condition
false and hence output will be “A”
printed by else part of the program.
2.str[i]=B.
resulting in ASCII value of 66.
So, str[i]-‘A’ will result in 1 as 66-65=1.
And, 1<25 which makes the if condition
false and hence output will be “B”
printed by else part of the program.
3.str[i]=a.
resulting in ASCII value of 97.
So, str[i]-‘A’ will result in 32 as 97-
65=32.
And, 32>25 which makes the if
condition
true and hence output will be “a”
printed by if part of the program.
4.str[i]=z.
resulting in ASCII value of 122.
So, str[i]-‘A’ will result in as 122-65=57.
And, 57>25 which makes the if
condition
true and hence output will be “z”
printed by if part of the program.

The reason why we are taking 25and not any other number is that there are 26 uppercase characters and 26 lowercase characters so if a given characters deflect more than 25 from ‘A’ then for sure it doesn’t belong to the uppercase character group.

1 Like

hey…output for case 3 and case 4 will be small “a” and small “z” right…and we are taking 25 cause we are starting from 0…so obviously between 0 to 25 all the characters comes…and hence the condition…" > 25 "…right ???

Somewhat. As we are taking 65,‘A’ as our base so a character deflecting more than 25 won’t atleast be an uppercase character. In this particular problem we are given only uppercase, lowercase and some special characters so, if a character isn’t in the range A-Z then it must be an uppercase character(special characters are already ruled out by previous “if” statements) .

Got it !!! Thank you so much for replying.