substring


Submit solution

Points: 40 (partial)
Time limit: 1.0s
Memory limit: 256M

Authors:
Problem type
Allowed languages
Java 19, Java 8

題目說明

請輸入一字串,可包含空格,之後輸入一整數,輸出此整數前與後但是不包含整數位的分割字串

輸入限制 可包含空格的字串,正整數

輸入

字串,表示分割位置的正整數

輸出

分割位置前的字串 分割位置後的字串

測試資料0 輸入

hello world 
6

測試資料0 輸出

hello  orld

測試資料1 輸入

ddddd ddddd 
1

測試資料1 輸出

d ddd ddddd

Comments


  • 0
    scu09156238  commented on April 12, 2024, 3:37 p.m.

    題解

    import java.util.*;
    
    public class t03281 {
        public static void main(String[] args) {
            // call a function to increment 0.5
            Scanner in = new Scanner(System.in);
            String s = in.nextLine();
            int k = in.nextInt();
            String substring = s.substring(0, k);
            String substring2 = s.substring(k + 1);
            System.out.println(substring + " " + substring2);
            in.close();
        }
    }