codeup-字符串的查找删除

1808: 字符串的查找删除

Time Limit: 1 Sec  Memory Limit: 32 MB
Submit: 2002  Solved: 574
[Submit][Status][Web Board][Creator:Imported]

Description

给定一个短字符串(不含空格),再给定若干字符串,在这些字符串中删除所含有的短字符串。

Input

输入只有1组数据。
输入一个短字符串(不含空格),再输入若干字符串直到文件结束为止。

Output

删除输入的短字符串(不区分大小写)并去掉空格,输出。

Sample Input

in
#include
int main()
{

printf(" Hi ");
}

Sample Output

#clude
tma()
{

prtf("Hi");
}

HINT

注:将字符串中的In、IN、iN、in删除。

 1 #include <stdio.h>
 2 #include <string.h>
 3
 4 int main(){
 5     char c[100];
 6     char s[1000];
 7     gets(c);
 8     int len1 = strlen(c), len2;
 9     //将c[i]全部转化为小写
10     for(int i=0; i<len1; i++){
11         if(c[i]>=‘A‘&&c[i]<=‘Z‘){
12             c[i] = c[i] + 32;
13         }
14     }
15     while(gets(s)){
16         len2 = strlen(s);
17         if(len2>=len1){
18             //对这个匹配过程不是很理解
19             for(int i=0, k=0; i<len2; ){
20                 //在匹配时,i不变,不匹配时,i自增!
21                 if(s[i+k]==c[k] || s[i+k]==c[k]-32){
22                     k++;
23                     if(k==len1){
24                         i = i + k; //在后k项满足时,i增加k
25                         k = 0;
26                     }
27                 }else{
28                     if(s[i]!=‘ ‘){
29                         printf("%c", s[i]);
30                     }
31                     i++;
32                     k = 0;
33                 }
34             }
35         }else{
36             for(int i=0; i<len2; i++){
37                 if(s[i]!=‘ ‘){
38                     printf("%c", s[i]);
39                 }
40             }
41         }
42         printf("\n");
43     }
44     return 0;
45 }

原文地址:https://www.cnblogs.com/heyour/p/12149886.html

时间: 2024-08-29 07:44:04

codeup-字符串的查找删除的相关文章

字符串的查找删除---C++中string.find()函数与string::npos

给定一个短字符串(不含空格),再给定若干字符串,在这些字符串中删除所含有的短字符串 输入: 输入只有一组数据 输入一个短字符串(不含空格),再输入若干字符串直到文件结束为止 输出: 删除输入的短字符串(不区分大小写)并去掉空格 #include <stdio.h> #include <string> #include <iostream> #include <ctype.h> using namespace std; int main() { char st

题目1168:字符串的查找删除

时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5092 解决:2097 题目描述: 给定一个短字符串(不含空格),再给定若干字符串,在这些字符串中删除所含有的短字符串. 输入: 输入只有1组数据.输入一个短字符串(不含空格),再输入若干字符串直到文件结束为止. 输出: 删除输入的短字符串(不区分大小写)并去掉空格,输出. 样例输入: in #include int main() { printf(" Hi "); } 样例输出: #clude tma() { prtf(&q

2009年北航:字符串的查找删除

题目描述: 给定一个短字符串(不含空格),再给定若干字符串,在这些字符串中删除所含有的短字符串. 输入: 输入只有1组数据.输入一个短字符串(不含空格),再输入若干字符串直到文件结束为止. 输出: 删除输入的短字符串(不区分大小写)并去掉空格,输出. 样例输入: in #include int main() { printf(" Hi "); } 样例输出: #clude tma() { prtf("Hi"); } 提示: 注:将字符串中的In.IN.iN.in删除

字符串的查找删除

题目描述 给定一个短字符串(不含空格),再给定若干字符串,在这些字符串中删除所含有的短字符串. 输入 输入只有1组数据. 输入一个短字符串(不含空格),再输入若干字符串直到文件结束为止. 输出 删除输入的短字符串(不区分大小写)并去掉空格,输出. 样例输入 in #include int main() { printf(" Hi "); } 样例输出 #clude tma() { prtf("Hi"); } 提示 注:将字符串中的In.IN.iN.in删除. #in

实现字符串的查找和替换

在字符串中查找目标字符串并将其替换为指定字符串,返回替换的次数.接口为 int find_str_replace(char *&str,const char *find_str,const char *replace_str) 将str中所有find_str替换为replace_str.要求不利用STL,c实现代码如下: #include<stdio.h> #include<string.h> #include<stdlib.h> //查找str从fromwhe

*字符串-01. 在字符串中查找指定字符

1 /* 2 * Main.c 3 * D1-字符串-01. 在字符串中查找指定字符 4 * Created on: 2014年8月18日 5 * Author: Boomkeeper 6 *****部分通过****** 7 */ 8 9 #include <stdio.h> 10 11 int mysearch(char ch, const char str[], int length) { 12 13 int j, ret = -1; 14 15 for (j = 0; j < le

字符串中查找子串

使用C语言编写程序: 1.在字符串中查找一个指定的字符第一次出现的位置,并返回字符所在的位置,如果不存在则返回NULL 具体实现如下: char* strchr(char const *str, int ch) { char* st = (char*)str; while (st) { if (*st == ch) return st; st++; } return NULL; } 2.在字符串中查找一个指定的字符串第一次出现的位置,并返回字符所在的位置,如果不存在则返回NULL 具体实现如下:

在字符串中查找指定字符

输入一个字符串S,再输入一个字符c,要求在字符串S中查找字符c.如果找不到则输出“Not found”:若找到则输出字符串S中从c开始的所有字符. 输入格式: 输入在第1行中给出一个不超过80个字符长度的.以回车结束的非空字符串:在第2行中给出一个字符. 输出格式: 在一行中按照题目要求输出结果. 输入样例1: It is a black box b 输出样例1: black box 输入样例2: It is a black box B 输出样例2: Not found #include<std

模拟实现在一个字符串中查找一个字符串

在标准库中有一个函数strstr()用于在一个字符串中查找一个规定的字符串,这个函数可以模拟实现一下,代码如下: #include <stdio.h> #include <assert.h> char *my_strstr(const char str[],const char strstr[]) {  int i = 0,j = 0,k = 0;  assert(str != NULL);  assert(strstr != NULL);  for(i = 0;str[i] !=