求字符在字符串中出现的次数
来源:互联网 发布:化工流程图软件 编辑:程序博客网 时间:2024/06/05 08:09
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str;
char reschar[50];
reschar[0]='\0';
getline(cin,str);
int len=str.length ();
int count=1;
int k;
for(k=0;k<len;k++)
{
if(str[k+1]==str[k])
count++;
else
{
sprintf(reschar+strlen(reschar),"%c%d",str[k],count);
count=1;
}
}
if(str[k]==str[k-1])
count++;
else
count=1;
sprintf(reschar+strlen(reschar),"%c%d",str[k],count);
cout<<reschar<<endl;
return 0;
}
#include<string>
using namespace std;
int main()
{
string str;
char reschar[50];
reschar[0]='\0';
getline(cin,str);
int len=str.length ();
int count=1;
int k;
for(k=0;k<len;k++)
{
if(str[k+1]==str[k])
count++;
else
{
sprintf(reschar+strlen(reschar),"%c%d",str[k],count);
count=1;
}
}
if(str[k]==str[k-1])
count++;
else
count=1;
sprintf(reschar+strlen(reschar),"%c%d",str[k],count);
cout<<reschar<<endl;
return 0;
}
- 求字符在字符串中出现的次数
- 求一个字符串中每个字符出现的次数
- Java求字符串中出现次数最多的字符
- 求字符串中出现次数最多的字符
- 求字符串中出现次数最多的字符及其出现次数
- 一个字符在字符串中出现的次数
- 统计某字符在某字符串中出现的次数
- ORACLE计算字符在字符串中出现的次数
- 计算字符在字符串中出现的次数
- 正则-某字符在字符串中出现的次数
- [SQL]计算字符在字符串中出现的次数
- 获取某个字符在字符串中出现的次数
- C++查找字符在字符串中出现的次数
- php统计所有字符在字符串中出现的次数
- ORACLE计算字符在字符串中出现的次数
- 统计某字符在字符串中出现的次数
- 某字符在某字符串中出现的次数
- 找出给定字符在字符串中出现的次数
- Unity3D 中保存或读取数组的方法
- 体会Python之独具匠心:Python XML PRC server多线程实现及其原理
- C++链式栈的简单实现(只有基本功能)
- 用MyEclipse引入已有项目出现问题
- python使用HTMLParser保存网页图片
- 求字符在字符串中出现的次数
- Java关键字final、static使用总结
- 在Asp.net MVC模式下实现网站地图导航
- Oracle expdp 过滤和并行
- 数据结构——链栈的基本操作
- A+B for Input-Output Practice (VIII)
- iOS 监测网络。
- Android4.2 CTS测试详解
- nginx+linux+mysql+php 增加gd库扩展