时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:6278
解决:2623
题目描述:给定一个短字符串(不含空格),再给定若干字符串,在这些字符串中删除所含有的短字符串。
输入:输入只有1组数据。 输入一个短字符串(不含空格),再输入若干字符串直到文件结束为止。
输出:删除输入的短字符串(不区分大小写)并去掉空格,输出。
样例输入: in #include int main() { printf(" Hi "); } 样例输出: #clude tma() { prtf("Hi"); } 提示:注:将字符串中的In、IN、iN、in删除。
解题过程:不会做,找的答案,但是有一些地方还是看不懂!郁闷。。。。有待进步!!!
源代码:
? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 #include<iostream> #include<string> #include<ctype.h> #include<stdio.h> using namespace std; int main() { char str[101]; gets (str); string a=str; int i; for (i=0;i<a.size();i++){ a[i]= tolower (a[i]); } while ( gets (str)){ string b=str,c=b; for (i=0;i<b.size();i++) { b[i]= tolower (b[i]); } int t=b.find(a,0); while (t!=string::npos) { c.erase(t,a.size()); b.erase(t,a.size()); t=b.find(a,t); } t=c.find( ' ' ,0); while (t!=string::npos){ c.erase(t,1); t=c.find( ' ' ,0); } cout<<c<<endl; } } /************************************************************** Problem: 1168 User: kaoyandaren123 Language: C++ Result: Accepted Time:0 ms Memory:1520 kb ****************************************************************/
