北航2009机试——字符串的查找删除
2016-06-09 12:47
288 查看
题目1168:字符串的查找删除
时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:4866
解决:1990
题目描述:
给定一个短字符串(不含空格),再给定若干字符串,在这些字符串中删除所含有的短字符串。
输入:
输入只有1组数据。
输入一个短字符串(不含空格),再输入若干字符串直到文件结束为止。
输出:
删除输入的短字符串(不区分大小写)并去掉空格,输出。
样例输入:
样例输出:
提示:
注:将字符串中的In、IN、iN、in删除。
从缓冲区一个一个读入字符,然后比较读入字符和模式字符串,比较他们的tolower()小写转换结果是否相等。
因为已经说了是短字符串,所以不要考虑KMP等等方法就可以求解。
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
char p[100];
char ch;
char t[1000][1000];
int main()
{
scanf("%s",p);
int len = strlen(p);
int i = 0;
ch = getchar();
while((ch=getchar())!=EOF)
{
if(tolower(ch)==tolower(p[i]))
{
i++;
if(i>=len) i=0;
}
else
{
if(i==0)
{
if(ch!=' ')putchar(ch);
}
else
{
for(int k=0;k<i;k++)
{
putchar(p[k]);
}
i = 0;
if(ch!=' ')putchar(ch);
}
}
}
return 0;
}
时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:4866
解决:1990
题目描述:
给定一个短字符串(不含空格),再给定若干字符串,在这些字符串中删除所含有的短字符串。
输入:
输入只有1组数据。
输入一个短字符串(不含空格),再输入若干字符串直到文件结束为止。
输出:
删除输入的短字符串(不区分大小写)并去掉空格,输出。
样例输入:
in #include int main() { printf(" Hi "); }
样例输出:
#clude tma() { prtf("Hi"); }
提示:
注:将字符串中的In、IN、iN、in删除。
从缓冲区一个一个读入字符,然后比较读入字符和模式字符串,比较他们的tolower()小写转换结果是否相等。
因为已经说了是短字符串,所以不要考虑KMP等等方法就可以求解。
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
char p[100];
char ch;
char t[1000][1000];
int main()
{
scanf("%s",p);
int len = strlen(p);
int i = 0;
ch = getchar();
while((ch=getchar())!=EOF)
{
if(tolower(ch)==tolower(p[i]))
{
i++;
if(i>=len) i=0;
}
else
{
if(i==0)
{
if(ch!=' ')putchar(ch);
}
else
{
for(int k=0;k<i;k++)
{
putchar(p[k]);
}
i = 0;
if(ch!=' ')putchar(ch);
}
}
}
return 0;
}
相关文章推荐
- 几张图
- Rotate Array
- 使用tiled-0.16.1创建地图用于cocos2dx
- eclipse ctrl 无法关联代码 解决
- etrace 跟踪 nginx之HTTP请求流程
- codeforce 510C Fox And Names (拓扑排序)
- 典型用户
- Implement Queue using Stacks
- cocoaPods 的使用
- Android环境搭建
- equals函数的作用笔记Mars
- 【Linux】linux常用基本命令
- Add Digits
- Android 中注解view (仿butterknife)
- 第9周项目1-②用复制构造函数体验深复制
- 菠萝叶粽子
- 对称加密和分组加密中的四种模式(ECB、CBC、CFB、OFB)
- 【深入Java虚拟机】之二:Java垃圾回收机制
- 我和高考--不得不说的故事
- c++ 1000内的素数