One day, Jojo wants to send a secret message to his friend. Jojo has a sentence consists of alphabet and whitespace characters. Jojo wants to change all the alphabets into capital letter, then change some alphabets into numbers.
I = 1, R = 2, E = 3, A = 4, S = 5, G = 6, T = 7, B = 8, P = 9, O = 0
Help Jojo to change his sentence.
Format Input :
Input consists of 1 sentence S in one line. The sentence only contains alphanumeric character and whitespace.
Format Output :
Output one line of sentence, the conversion result from the initial sentence.
Constraints :
1 ≤|S|≤ 10.000
Get input string.
Examine each char in turn - perhaps using a loop.
Change each letter to capital
Then, if the letter is one of the special letters, change it the to appropriate number
I would note that this being C++, you could do yourself a favour and use string rather than an array, getline rather than gets, cout rather than printf. At the moment, you're writing C code.
we do not mind to help C (esp simple questions), but we get a lot of people mixing C into C++ code and try to help them stop doing that :)
this problem begs a lookup table. (which many problems do. they are fast and easy to code).
make a nice char array of 256 entries. set it to 0-255 to start (its the ascii table, to start)
then manually correct it:
for(int x = 'a'; x <= 'z'; x++)
table[x] = 'A'+(x-'a'); //or if you have toupper or whatever use it here.
then again correct the others:
table['I'] = '1'; //etc
and then its easy:
for each letter in the string:
outstring[letter] = table[inputstring[letter]];