字符串s中出现的C字符删除的不同实现方法
来源:互联网 发布:网络监控摄像机多少钱 编辑:程序博客网 时间:2024/05/19 00:37
1
2 #include <stdio.h>
3 #include <string.h>
4 void delchar(char s[], char c);
5 int main()
6 {
7 char cc,ch[80];
8
9 cc=getchar();
10 getchar();//erase Enter
11 gets(ch);
12 delchar(ch,cc);
13 printf("%s",ch);
14
15 return 0;
16 }
17 void delchar(char s[], char c)
18 {
19 int i,k,len;
20 len=strlen(s);
21 for(i=0;s[i]!='/0';)
22 {
23 if(s[i]==c)
24 {
25 for(k=i;k<len;k++)
26 {
27 s[k]=s[k+1];
28 }
29 if (s[i]!=c)
30 {
31 i++;
32 }
33 }
34 else
35 i++;
36 }
37 }
38
39
C++ STL version
1 #include <vector>
2 #include <cstdio>
3 #include <cstring>
4 #include <iostream>
5 using namespace std;
6 int main()
7 {
8 char cc,ch[80];
9 cin>>cc;
10 cin>>ch;
11
12 vector<char>v(ch,ch+strlen(ch));
13 for (vector<char>::iterator it = v.begin();it!=v.end();)
14 {
15 if (*it==cc)
16 {
17 it=v.erase(it);
18 }
19 else
20 it++;
21
22 }
23
24 for (vector<char>::iterator it=v.begin();it!=v.end();it++)
25 {
26 cout<<*it;
27 }
28
29 return 0;
30 }
31
32
1 #include <iostream>
2 #include <iterator>
3 #include <algorithm>
4 #include <functional>
5
6 using namespace std;
7 int main()
8 {
9
10 remove_copy_if(istream_iterator<char>(cin), istream_iterator<char>(), ostream_iterator<char>(cout), bind1st(equal_to<char>(),cin.get()));
11 return 0;
12 }
13
1
2 int main()
3 {
4 remove_copy(istream_iterator<char>(cin), istream_iterator<char>(), ostream_iterator<char>(cout), cin.get());
5 }
6
7
- 字符串s中出现的C字符删除的不同实现方法
- C++实现删除字符串中所有重复出现的字符
- 实现删除字符串中出现次数最少的字符
- 18:实现删除字符串中出现次数最少的字符
- s.indexOf(c)的用法,在字符串“s”中第一次出现字符“c”的位置。
- 删除字符串中出现最少的字符
- C语言实现删除字符串中特定的字符
- c语言实现找到字符串中出现最多的字符
- 在字符串中删除另一个字符串中出现的字符
- 在字符串中删除另一个字符串中出现的字符
- 在字符串中删除另一个字符串中出现的字符
- 实现删除字符串中出现次数最少的字符,若多个字符出现次数一样,则都删除。
- 实现删除字符串中出现次数最少的字符,若多个字符出现次数一样,则都删除。
- 统计输入字符串中各不同字符出现的频度
- C语言小程序—找出字符串中出现次数最少的字符并删除
- 【C语言】 两种不同的方法在一个字符串中找指定的字符
- 删除字符串中出现的最少的字符
- 华为OJ----删除字符串中出现的最少的字符
- It is to celebrate my blog's first day
- C++ primer English Fourth edition page 349 exercises
- 腾讯企业QQ服务器完全架设指南
- 什么是存款准备金以及存款准备金率
- 免费在线生成LOGO和小站标的网站
- 字符串s中出现的C字符删除的不同实现方法
- Redhat Enterprise Linux as 4 update 3
- 数据库设计范式
- 让CSDN 博客使用Windows Live Writer _初体验
- 可嵌套的C语言异常处理机制
- CRC16计算方法
- 大家好!
- Analys 版本历史
- JS正则表达式解析出网址中的域名部分