File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
Beginner/Whats in the Name (NITIKA) Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ process . stdin . resume ( ) ;
2+ process . stdin . setEncoding ( "utf8" ) ;
3+
4+ let data = "" ;
5+
6+ process . stdin . on ( "data" , function ( chunk ) {
7+ data += chunk . toString ( ) ;
8+ } ) ;
9+
10+ process . stdin . on ( "end" , function ( ) {
11+ runTestCases ( ) ;
12+ } ) ;
13+
14+ function runTestCases ( ) {
15+ let lines = data . split ( "\n" ) ; // Getting all the inputs
16+ let length = 0 ;
17+ const t = parseInt ( lines [ length ++ ] ) ; // Getting the number of test cases
18+
19+ for ( let i = 0 ; i < t ; i ++ ) {
20+ const name = lines [ length ++ ] ;
21+ const partsOfName = name . split ( " " ) ;
22+
23+ if ( partsOfName . length === 1 ) {
24+ const lastName = partsOfName [ 0 ] . toLowerCase ( ) ;
25+ console . log ( lastName . charAt ( 0 ) . toUpperCase ( ) + lastName . slice ( 1 ) ) ;
26+ } else if ( partsOfName . length === 2 ) {
27+ const firstName = partsOfName [ 0 ] ;
28+ const lastName = partsOfName [ 1 ] . toLowerCase ( ) ;
29+ console . log (
30+ firstName . charAt ( 0 ) . toUpperCase ( ) +
31+ ". " +
32+ lastName . charAt ( 0 ) . toUpperCase ( ) +
33+ lastName . slice ( 1 )
34+ ) ;
35+ } else {
36+ const firstName = partsOfName [ 0 ] ;
37+ const middleName = partsOfName [ 1 ] ;
38+ const lastName = partsOfName [ 2 ] . toLowerCase ( ) ;
39+ console . log (
40+ firstName . charAt ( 0 ) . toUpperCase ( ) +
41+ ". " +
42+ middleName . charAt ( 0 ) . toUpperCase ( ) +
43+ ". " +
44+ lastName . charAt ( 0 ) . toUpperCase ( ) +
45+ lastName . slice ( 1 )
46+ ) ;
47+ }
48+ }
49+ }
You can’t perform that action at this time.
0 commit comments