8
8
#include <stdlib.h>
9
9
#include <string.h>
10
10
11
- char * HACKERRANK_WARMUP_lastN (const char * s , unsigned long n ) {
12
- unsigned long len = strlen (s );
13
- if (n > len ) {
14
- return NULL ;
15
- }
16
- if (n == 0 ) {
17
- return NULL ;
18
- }
19
-
20
- char * result = (char * )malloc ((n + 1 ) * sizeof (char ));
21
- if (result == NULL ) {
22
- return NULL ;
23
- }
24
-
25
- strncpy (result , s + len - n , n );
26
-
27
- result [n ] = '\0' ;
28
-
29
- return result ;
30
- }
31
-
32
11
char * HACKERRANK_WARMUP_getFirst (const char * s , unsigned long n ) {
33
12
return HACKERRANK_WARMUP_getStringFragment (s , strlen (s ), 0 , n );
34
13
}
@@ -61,8 +40,8 @@ char *HACKERRANK_WARMUP_getStringFragment(const char *s, unsigned long len,
61
40
}
62
41
63
42
char * HACKERRANK_WARMUP_timeConversion (const char * s ) {
64
- char * meridian = HACKERRANK_WARMUP_lastN (s , 2 );
65
- // char *meridian = HACKERRANK_WARMUP_getLast(s, 2);
43
+ // char *meridian = HACKERRANK_WARMUP_lastN(s, 2);
44
+ char * meridian = HACKERRANK_WARMUP_getLast (s , 2 );
66
45
67
46
// char *hour_str = HACKERRANK_WARMUP_firstN(s, 2);
68
47
char * hour_str = HACKERRANK_WARMUP_getFirst (s , 2 );
@@ -76,7 +55,7 @@ char *HACKERRANK_WARMUP_timeConversion(const char *s) {
76
55
strcpy (time_str , s );
77
56
char * temp_time_str ;
78
57
unsigned long time_str_len = strlen (time_str );
79
- temp_time_str = HACKERRANK_WARMUP_lastN (time_str , time_str_len - 2 );
58
+ temp_time_str = HACKERRANK_WARMUP_getLast (time_str , time_str_len - 2 );
80
59
free (time_str );
81
60
time_str = temp_time_str ;
82
61
temp_time_str = HACKERRANK_WARMUP_getFirst (time_str , time_str_len - 2 );
0 commit comments