九度 OJ 1049:字符串去特定字符

来源:互联网 发布:刘梓晨直播软件 编辑:程序博客网 时间:2024/05/21 19:37
题目1049:字符串去特定字符

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:9683

解决:4384

题目描述:

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

输入:

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

输出:

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

样例输入:
healloa
样例输出:
hello
来源:

2009年哈尔滨工业大学计算机研究生机试真题


字符串输入时尽量使用C++格式cin输入


#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main(){    string s;    while(cin>>s){        char c;        cin>>c;        for(int i=0;i<s.length();i++){            if(s[i]!=c) {                printf("%c",s[i]);            }        }        printf("\n");    }}/**************************************************************    Problem: 1049    User: th是个小屁孩    Language: C++    Result: Accepted    Time:0 ms    Memory:1520 kb****************************************************************/


0 0
原创粉丝点击