HDOJ/HDU 1984 Mispelling4(删除第n个字符~)

Problem Description
Misspelling is an art form that students seem to excel at. Write a program that removes the nth character from an input string.

Input
The first line of input contains a single integer N, (1 ≤ N ≤ 1000) which is the number of datasets that follow.
Each dataset consists of a single line of input containing M, a space, and a single word made up of uppercase letters only. M will be less than or equal to the length of the word. The length of the word is guaranteed to be less than or equal to 80.

Output
For each dataset, you should generate one line of output with the following values: The dataset number as a decimal integer (start counting at one), a space, and the misspelled word. The misspelled word is the input word with the indicated character deleted.

Sample Input
4
4 MISSPELL
1 PROGRAMMING
7 CONTEST
3 BALLOON

Sample Output
1 MISPELL
2 ROGRAMMING
3 CONTES
4 BALOON

大水题!!!
就是一个字符串删除第n(从1开始)个字符就可以了。

import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int p=1;
        int t =sc.nextInt();
        while(t-->0){
            int a = sc.nextInt();
            String str=sc.next();
            System.out.print((p++)+" ");
            for(int i=0;i<str.length();i++){
                if(i!=(a-1)){
                    System.out.print(str.charAt(i));
                }
            }
            System.out.println();
        }
    }
}
时间: 2024-09-06 02:16:53

HDOJ/HDU 1984 Mispelling4(删除第n个字符~)的相关文章

HDOJ/HDU 2140 Michael Scofield&amp;#39;s letter(字符转换~)

Problem Description I believe many people are the fans of prison break. How clever Michael is!! In order that the message won't be found by FBI easily, he usually send code letters to Sara by a paper crane. Hence, the paper crane is Michael in the he

Linux系统中tr命令删除和替换文本字符的基本用法

  通过使用 tr,您可以非常容易地实现 sed 的许多最基本功能.您可以将 tr 看作为 sed 的(极其)简化的变体:它可以用一个字符来替换另一个字符,或者可以完全除去一些字符.您也可以用它来除去重复字符.这就是所有 tr 所能够做的. tr用来从标准输入中通过替换或删除操作进行字符转换.tr主要用于删除文件中控制字符或进行字符转换.使用tr时要转换两个字符串:字符串1用于查询,字符串2用于处理各种转换.tr刚执行时,字符串1中的字符被映射到字符串2中的字符,然后转换操作开始. 带有最常用选

jquery 删除字符串最后一个字符的方法解析

 本篇文章主要是对jquery 删除字符串最后一个字符的方法进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助 字符串:var s = "1,2,3,4,5,"   目标:删除最后一个 ","   方法: s=s.substring(0,s.Length-1):   字符串:var s2 = "img/upload/123.jpg"   目标:获取文件名(不包含后缀名)   方法: s2=s2.substring(s2.lastIndexO

JS 删除字符串最后一个字符的实现代码

  本篇文章主要是对JS删除字符串最后一个字符的实现代码进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助 字符串:string s = "1,2,3,4,5," 目标:删除最后一个 "," 方法: 用的最多的是substring,这个也是我一直用的 s=s.substring(0,s.length-1)  

JS删除字符串中重复字符方法

 这篇文章主要介绍了JS如何删除字符串中重复字符,需要的朋友可以参考下  代码如下: <!DOCTYPE html>  <html>  <head>  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">  </script>  <script>  $(document).ready(function(){  $(&quo

PHP实现删除字符串中任何字符的函数_php技巧

本文实例讲述了PHP实现删除字符串中任何字符的函数.分享给大家供大家参考.具体如下: function delStr($start, $end, $orgenStr) { //读取要删除字符位置的前一部分字符串,并赋值给$temp //strpos读取字符第一次出现的位置 //substr读取指定开始与结束位置的子字符串 //echo $before."-". $last; $temp=$orgenStr; while(strpos($temp, $start) &&

php rtrim(),substr()删除字符串最一个字符

我们利用这两个函数来删除字符串最后一个字符是有说法的,rtrim他有默认删除空格和一些特殊字符,但你也可以删除指定字符,页substr我们是取字符长度,自然只要取字符长度减一就行了如下实例. */ $str ='abcea'; echo rtrim($str,'a'); //方法二 echo '<br />'.substr($str,0,strlen($str)-1);

HDOJ/HDU 1161 Eddy&amp;#39;s mistakes(大写字母转换成小写字母)

Problem Description Eddy usually writes articles ,but he likes mixing the English letter uses, for example "computer science" is written frequently "coMpUtEr scIeNce" by him, this mistakes lets Eddy's English teacher be extremely disco

HDOJ/HDU 1087 Super Jumping! Jumping! Jumping!(经典DP~)

Problem Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now. The game can be played by two or more t