You are not logged in. Please login at www.codechef.com to post your questions!

×

NITIKA - editorial

PROBLEM LINK:

Practice
Contest

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

DIFFICULTY:

Cakewalk

PREREQUISITES:

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".

asked 04 Jul '17, 19:13

deadwing97's gravatar image

3★deadwing97
1181134
accept rate: 0%

edited 17 Jul '17, 16:40

admin's gravatar image

0★admin ♦♦
19.8k350498541


if($i == $count-1 ) echo '.'.ucwords($value[$i]); else echo ucwords($value[$i][0]); } }

}

link

answered 18 Jul '17, 09:05

jayesh_92's gravatar image

0★jayesh_92
1
accept rate: 0%

if($i == $count-1 ) echo '.'.ucwords($value[$i]); else echo ucwords($value[$i][0]); } } }

link

answered 19 Jul '17, 20:50

pushpanjali26's gravatar image

0★pushpanjali26
1
accept rate: 0%

if($i == $count-1 ) echo '.'.ucwords($value[$i]); else echo ucwords($value[$i][0]); } } }

link

answered 23 Jul '17, 12:08

jawed4u's gravatar image

0★jawed4u
1
accept rate: 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)

link

answered 28 Jul '17, 15:25

maths_nerd's gravatar image

0★maths_nerd
1
accept rate: 0%

include<stdio.h>

include<string.h>

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; }

link

answered 06 Feb '18, 13:10

s13_0477's gravatar image

2★s13_0477
1
accept rate: 0%

include<stdio.h>

include<string.h>

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;

}

link

answered 06 Feb '18, 13:18

sreeram14's gravatar image

2★sreeram14
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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