Problem:
Score: 200 points

Problem Statement

We have a string S consisting of lowercase English letters.

If the length of S is at most K, print S without change.

If the length of S exceeds K, extract the first K characters in S, append ... to the end of them, and print the result.

Constraints

K is an integer between 1 and 100 (inclusive).

S is a string consisting of lowercase English letters.

The length of S is between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

K
S

Output

Print a string as stated in Problem Statement.

Sample Input 1

7
nikoandsolstice

Sample Output 1

nikoand...

nikoandsolstice has a length of 15, which exceeds K=7.

We should extract the first 7 characters in this string, append ... to the end of them, and print the result nikoand....

Sample Input 2

40
ferelibenterhominesidquodvoluntcredunt

Sample Output 2

ferelibenterhominesidquodvoluntcredunt

The famous quote from Gaius Julius Caesar.

Solution in C (GCC 9.2.1) (judge verdict: Accepted)


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

void InsertDots(char * inputString, int * inputK)
{
    char * outputString = malloc(255 * sizeof(char));
    char * dotString = "...";
    
    strncpy(outputString,inputString,*inputK);
    strcat(outputString, dotString);
    
    
    printf("%s \n", outputString);
}

void CheckLength(char * inputString, int * inputK)
{
    long stringLength = strlen(inputString);
    
    if(stringLength > *inputK)
    {
        InsertDots(inputString, inputK);
    }
    else
    {
        printf("%s \n", inputString);
    }
}

void ReadInputS(char * inputString)
{
    //printf("Enter your string: \n");
    scanf("%s", inputString);
}

void ReadInputK(int * inputK)
{
    //printf("Enter value of K: \n");
    scanf("%d", inputK);
    
    while (*inputK > 100)
    {
        printf("Wrong input, value needs to be less 100 \n");
        ReadInputK(inputK);
        if(*inputK <= 100)
        {
          break;
        }
    }
}

int main(int argc, const char * argv[])
{

    int *inputK = malloc(255 * sizeof(int));
    char *inputString = malloc(255 * sizeof(char));
    
    
    ReadInputK(inputK);
    ReadInputS(inputString);
    CheckLength(inputString, inputK);
    
    return 0;
}