8986. Delete a fragment

 

Given a string of Latin letters and spaces. Delete in it all characters with indices from n to m inclusive. Indexation starts from 0.

 

Input. The first line contains text of no more than 1000 Latin letters and spaces. Second line contains two integers n and m (n ≤ m).

 

Output. Print the updated string.

 

Sample input

Sample output

abrakadabra

3 6

abrabra

 

 

SOLUTION

string

 

Algorithm analysis

Concatenate the substrings s[0; n – 1] and s[m + 1; len], where len is the length of input string.

 

The problem can be solved in another way, by copying the substring s[m + 1] to position s[n].

 

Example

In this problem the substring s[3..6] must be deleted. To do this, one need to copy the data starting from the character s[7] and till the zero byte inclusive, into position s[3].

 

Algorithm realization

Declare char array.

 

char s[1001];

 

Read the input data.

 

gets(s);

scanf("%d %d", &n, &m);

 

Copy a substring.

 

strcpy(s + n, s + m + 1);

 

Print the answer.

 

puts(s);

 

Algorithm realization – С++

 

#include <iostream>

#include <string>

using namespace std;

 

int i, n, m;

string s;

 

int main(void)

{

  getline(cin, s);

  cin >> n >> m;

  s = s.substr(0, n) + s.substr(m + 1);

  cout << s << endl;

  return 0;

}

 

Java realization

 

import java.util.*;

 

public class Main

{

  public static void main(String[] args)

  {

    Scanner con = new Scanner(System.in);

    String s = con.nextLine();

    int n = con.nextInt();

    int m = con.nextInt();

 

    s = s.substring(0,n) + s.substring(m+1);

 

    System.out.println(s);   

    con.close();

  }

}

 

Python realization

 

s = input()

a, b = map(int,input().split())

print (s[:a] + s[b+1:])