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

2 Likes
<?php $fp = fopen("php://stdin","r"); $value1 = fgets($fp); $members = array(); while (!feof($fp)) { $members[] = fgets($fp); } for($i = 0;$i <= $value1-1;$i++) { $value = explode(" ",$members[$i]); $count = count($value); if($count < 2) { echo ucwords($value[$count-1]); } else { for($i = 0;$i <= $count -1;$i++) { if($i == $count-1 ) echo '.'.ucwords($value[$i]); else echo ucwords($value[$i][0]); } } }

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

if($i == $count-1 )
echo ‘.’.ucwords($value[$i]);
else
echo ucwords($value[$i][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)

#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main()
{

char str[100001];
int temp;
int i;
int t;
scanf("%d
“,&t);
while(t-- ){
gets(str);
temp=0;
for(i=0;i<strlen(str);i++){
if(str*==’ '){
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*));
}

printf("
");
}

return 0;
}

#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main()
{

char str[100001];
int temp;
int i;
int t;
scanf("%d

“,&t);
while(t-- ){
gets(str);
temp=0;
for(i=0;i<strlen(str);i++){
if(str*==’ '){
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*));
    }

printf("

");
}

return 0;

}

solved. :smiley: