×

# NITIKA - editorial

Author: Abhinav Jain
Primary Tester: Misha Chorniy
Editorialist: Hussain Kara Fallah

Cakewalk

None

# PROBLEM:

Given names of people. Each name may consist of at least one and at most three parts. You are asked to show the name with replacing the first two parts (if they exist) with the first letter of each (abbreviation) and followed by the last part (last name). Abbreviations should be upper case letters. Only the first letter of the last name should be in uppercase.

# EXPLANATION:

This problem is straight forward implementation (string manipulation). Each name will be given on a separate line, so we should read each line completely (one by one). We have to find the parts of each name and separate them from each other. Since each two consecutive parts are separated by a space,we should be looking for spaces in each line. The first space (if it exists) separates between the 1st and the 2nd part, the second space (if it exists) separates between the 2nd and the 3rd part. Finding spaces on each line would make us able to break our full name into parts (This can be done manually by a loop).

My solution uses stringstream (C++ class) which is very useful for parsing input and solves this problem easily. A brief explanation can be found here :stringstream

After breaking the name into parts we should capitalize the first letter of each part. We should output only the first letter of each part capitalized (except the last part). As for the last part, we must set its first letter to uppercase, and the rest of its letters to lowercase. After that, we can print it.

# AUTHOR'S AND TESTER'S SOLUTIONS:

AUTHOR's solution: Will be found here
TESTER's solution: Will be found here
EDITORIALIST's solution: Will be found here

This question is marked "community wiki".

1181134
accept rate: 0%

19.8k350498541

 0  if($i ==$count-1 ) echo '.'.ucwords($value[$i]); else echo ucwords($value[$i][0]); } }  } answered 18 Jul '17, 09:05 1 accept rate: 0%
 0 if($i ==$count-1 ) echo '.'.ucwords($value[$i]); else echo ucwords($value[$i][0]); } } } answered 19 Jul '17, 20:50 1 accept rate: 0%
 0 if($i ==$count-1 ) echo '.'.ucwords($value[$i]); else echo ucwords($value[$i][0]); } } } answered 23 Jul '17, 12:08 0★jawed4u 1 accept rate: 0%
 0 var myName= ['s','S','o','O','u','U','b','B','h','H','a','A','g','G','y','Y','a','A' 'Shekhar','shekhar'] var listItem = myName[1] ,[18] console.log (listItem) answered 28 Jul '17, 15:25 1 accept rate: 0%

# include<ctype.h>

int main() {

char str[100001]; int temp; int i; int t; scanf("%d\n",&t); while(t-- ){ gets(str); temp=0; for(i=0;i<strlen(str);i++){ if(str[i]==' '){ printf("%c. ",toupper(str[temp])); temp=i+1;} }

printf("%c",toupper(str[temp])); for(i=temp+1;i<strlen(str);i++) { printf("%c",tolower(str[i])); }

printf("\n"); }

return 0; }

2★s13_0477
1
accept rate: 0%

# include<ctype.h>

int main() {

char str[100001];
int temp;
int i;
int t;
scanf("%d\n",&t);
while(t-- ){
gets(str);
temp=0;
for(i=0;i<strlen(str);i++){
if(str[i]==' '){
printf("%c. ",toupper(str[temp]));
temp=i+1;}
}

printf("%c",toupper(str[temp]));
for(i=temp+1;i<strlen(str);i++)
{
printf("%c",tolower(str[i]));
}

printf("\n");
}

return 0;


}

1
accept rate: 0%

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,852
×849
×229
×11

question asked: 04 Jul '17, 19:13

question was seen: 2,732 times

last updated: 06 Feb '18, 13:18