题目1049:字符串去特定字符

题目描述:

输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果。

输入:

测试数据有多组,每组输入字符串s和字符c。

输出:

对于每组输入,输出去除c字符后的结果。

样例输入:
heallo
a
样例输出:
hello
来源:
2009年哈尔滨工业大学计算机研究生机试真题
 1 import java.math.BigInteger;
 2 import java.util.Arrays;
 3 import java.util.Scanner;
 4
 5 public class Main{
 6     public static void main(String[]args){
 7     Scanner in=new Scanner(System.in);
 8     while(in.hasNext()){
 9        String s=in.nextLine();
10        String t=in.nextLine();
11        char c=t.charAt(0);
12        char[]s2c=s.toCharArray();
13        int len=s2c.length;
14        s="";
15        for(int i=0;i<len;i++){
16            if(s2c[i]==c) continue;
17            s+=s2c[i];
18        }
19         System.out.println(s);
20     }
21     }
22  }
23
24 /**************************************************************
25     Problem: 1049
26     User: 0000H
27     Language: Java
28     Result: Accepted
29     Time:80 ms
30     Memory:15416 kb
31 ****************************************************************/
时间: 2024-08-04 12:12:31

题目1049:字符串去特定字符的相关文章

1049.字符串去特定字符

题目描述: 输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果. 输入: 测试数据有多组,每组输入字符串s和字符c. 输出: 对于每组输入,输出去除c字符后的结果. 样例输入: heallo a 样例输出: hello #include<iostream> #include<cstring> using namespace std; int main(){ char s[10000],a; while(gets(s)){ cin>>a; for(int i=0;

题目1049:字符串去特定字符(简单字符判断)

题目链接:http://ac.jobdu.com/problem.php?pid=1049 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: // // 1049 字符串去特定字符.cpp // Jobdu // // Created by PengFei_Zheng on 26/04/2017. // Copyright © 2017 PengFei_Zheng. All rights reserved. // #include <s

九度oj 题目1049:字符串去特定字符

题目1049:字符串去特定字符 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:10173 解决:4611 题目描述: 输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果. 输入: 测试数据有多组,每组输入字符串s和字符c. 输出: 对于每组输入,输出去除c字符后的结果. 样例输入: heallo a 样例输出: hello 1 #include <iostream> 2 #include <string> 3 using namespace std; 4 5 i

字符串去特定字符-2009年哈尔滨工业大学计算机研究生机试真题

题目描述: 输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果. 输入: 测试数据有多组,每组输入字符串s和字符c. 输出: 对于每组输入,输出去除c字符后的结果. 样例输入: heallo    a 样例输出: hello 解题代码: 解法1:使用两个数组, 第二个数组存储去掉特定字符的字符串 #include <stdio.h> int main(){ char arr[200]; char arrNew[200]; char focus; while (scanf("%

哈工大机考:字符串去特定字符

时间限制:1秒 空间限制:32768K 题目描述 输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果. 输入描述: 测试数据有多组,每组输入字符串s和字符c. 输出描述: 对于每组输入,输出去除c字符后的结果. 输入例子: heallo a 输出例子: hello思路:这个没啥好说的照着做就行,但咱写的过程中遇到一个小问题:代码: #include <iostream> #include <stdio.h> using namespace std; int main(){

九度OJ1049题-去特定字符(和1111题特别像)

题目1049:字符串去特定字符 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:11329 解决:5169 题目描述: 输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果. 输入: 测试数据有多组,每组输入字符串s和字符c. 输出: 对于每组输入,输出去除c字符后的结果. 样例输入: heallo a 样例输出: hello 来源: 2009年哈尔滨工业大学计算机研究生机试真题 1 #include <iostream> 2 #include <stdio.h>

转载:js实现统计字符串中特定字符出现个数的方法

//js统计字符串中包含的特定字符个数 function getPlaceholderCount(strSource) {   //统计字符串中包含{}或{xxXX}的个数   var thisCount = 0;   strSource.replace(/\{[xX]+\}|\{\}/g, function (m, i) {     //m为找到的{xx}元素.i为索引     thisCount++;   });   return thisCount; }

Java去除字符串首尾特定字符

工作中,由于mysql存储格式特定,字符串首尾均带有单引号,需要对首尾单引号做一个去除处理.我将此封装到一个公共的方法里,代码如下: 1 /** 2 * 去除首尾指定字符 3 * @param str 字符串 4 * @param element 指定字符 5 * @return 6 */ 7 public static String trimFirstAndLastChar(String str, String element){ 8 boolean beginIndexFlag = true

删除或替换字符串中特定字符

1 replace( ) replace()函数只有三个参数,第三个参数是最大替代次数 特别注意replace()函数作用完后,并没有改变原字符串 参考:https://www.runoob.com/python/att-string-replace.html 2 strip( ) strip() 方法用于移除字符串头尾指定的字符(默认为空格或换行符)或字符序列 参考:https://www.runoob.com/python/att-string-strip.html 3 lstrip( )