行程编码(atoi函数)
#include<iostream>
#include<string>
#include<vector>
using namespace std;
void jiema(string s)
{
cout << "解码之后为:" << endl;
for(int i = ; i < s.size(); i++)
{
if(s[i + ] == '*')
{
int j = i + ;
int len = ;
while(s[j + ] >= && s[j + ] <= )
{
len++;
j = j + ;
}
string temp = s.substr(i + , len);
int num = atoi(temp.c_str());
for(int k = ; k < num; k++)
{
cout << s[i];
}
i = j;
}
else
{
cout << s[i]; }
}
}
void bianma(string s)
{
vector<char>A;
int p = ;
int j = ;
for(; j < s.size();)
{
while(s[j] == s[j + ] && j < s.size())
{
p++;
j = j + ;
}
if(p >= )
{
A.push_back(s[j]);
A.push_back('*');
A.push_back(p);
p = ;
j = j + ;
}
else if(p < )
{
for(int k = ; k < p; k++)
{
A.push_back(s[j]);
}
p = ;
j = j + ;
}
}
cout << "编码之后为:" << endl;
for(int b = ; b < A.size(); b++)
{
if(A[b] >= && A[b] <= )
cout << int(A[b]);
else
cout << A[b];
}
cout << endl;
cout << "压缩比为:" << endl;
double y = double(A.size()) / s.size();
cout << y << endl;
}
void main()
{
cout << "请输入代码:①代码中含有数字表示需要解码解压缩②代码中不含数字表示需要编码压缩" << endl;
string s;
for(; cin >> s;)
{
int i = ;
for(; i < s.size(); i++)
{
if(s[i] >= && s[i] <= ) //解码
{
jiema(s);
break;
}
}
if(i == s.size())
{
bianma(s);
}
}
}
行程编码(atoi函数)的更多相关文章
- atoi()函数
原型:int atoi (const char *nptr) 用法:#include <stdlib.h> 功能:将字符串转换成整型数:atoi()会扫描参数nptr字符串,跳过前 ...
- C语言itoa()函数和atoi()函数详解(整数转字符C实现)
1.int/float to string/array: C语言提供了几个标准库函数,可以将任意类型(整型.长整型.浮点型等)的数字转换为字符串,下面列举了各函数的方法及其说明. ● itoa():将 ...
- 题目1003:A+B ---c_str(),atoi()函数的使用;remove , erase函数的使用
#include<stdio.h> #include<stdlib.h> int sw(char *a){ ,c=; while(a[i]){ ') c=c*+a[i]-'; ...
- atoi()函数的实现
atoi()函数的功能:将字符串转换成整型数:atoi()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负号才开始做转换,而再遇到非数字或字符串时('\0')才结束转化,并将结果返回( ...
- C语言itoa()函数和atoi()函数详解(整数转字符)
http://c.biancheng.net/cpp/html/792.html C语言提供了几个标准库函数,可以将任意类型(整型.长整型.浮点型等)的数字转换为字符串. 以下是用itoa()函数将整 ...
- C语言itoa函数和atoi 函数
C语言提供了几个标准库函数,可以将任意类型(整型.长整型.浮点型等)的数字转换为字符串.以下是用itoa()函数将整数转 换为字符串的一个例子: # include <stdio.h> ...
- 【C语言】模拟实现atoi函数
atoi(表示 ascii to integer)是把字符串转换成整型数的一个函数. atoi()函数会扫描参数 nptr字符串,跳过前面的空白字符(例如空格,tab缩进等,可以通过isspace( ...
- String to Integer (atoi) - 字符串转为整形,atoi 函数(Java )
String to Integer (atoi) Implement atoi to convert a string to an integer. [函数说明]atoi() 函数会扫描 str 字符 ...
- atoi()函数(转载)
atoi()函数 原型:int atoi (const char *nptr) 用法:#include <stdlib.h> 功能:将字符串转换成整型数:atoi()会扫描参数np ...
- 源码实现 --> atoi函数实现
atoi函数实现 atoi()函数的功能是将一个字符串转换为一个整型数值. 例如“12345”,转换之后的数值为12345,“-0123”转换之后为-123. #include <stdio.h ...
随机推荐
- 第一篇博客 用笨办法学python-14 提示和传递
# 代码如下: usr_name = input("")script = input("")prompt = '> 'print("hi %s, ...
- 控制ASP.NET Web API 调用频率
很多的api,例如GitHub’s API 都有流量控制的做法.使用速率限制,以防止在很短的时间量客户端向你的api发出太多的请求.例如,我们可以限制匿名API客户端每小时最多60个请求,而我们可以让 ...
- ABP理论学习之Nuget包
返回总目录 本篇目录 框架 测试基 ABP已经发布在Nuget上,这里是所有包的列表. 框架 Abp Abp系统的核心包.所有其他的包都依赖这个包. Abp.Web 提供了MVC和Web API都使用 ...
- 图片拾取器-PicPicker
最近报名参加了360前端星计划,想当一名前端实习生,学习更多更流行的前端知识.然后需要完成一个作业,才能进培训,进了培训还得看运气才能留下,流程不少.书归正传,请看: 课后作业题目 请从下面两个题目中 ...
- SQL Azure (17) SQL Azure V12 - 跨数据中心标准地域复制(Standard Geo-Replication)
<Windows Azure Platform 系列文章目录> 熟悉Microsoft Azure平台的读者都了解,Azure SQL Database提供不同等级的,跨数据中心的异地冗余 ...
- 《Entity Framework 6 Recipes》中文翻译系列 (24) ------ 第五章 加载实体和导航属性之查询内存对象
翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 5-4 查询内存对象 问题 你想使用模型中的实体对象,如果他们已经加载到上下文中, ...
- [翻译] AKKA笔记- ACTORSYSTEM (配置CONFIGURATION 与调度SCHEDULING) - 4(一)
原文在http://rerun.me/2014/10/06/akka-notes-actorsystem-in-progress/ 像我们前面看到的,我们可以用ActorSystem的actorof方 ...
- Angularjs学习---官方phonecat实例学习angularjs step0 step1
接下来一系列的文章都是学习https://docs.angularjs.org/tutorial的笔记,主要学习的angular-phonecat项目的实现,来介绍angularjs的使用. 1.下载 ...
- Eclipse 常用快捷键 (动画讲解)
Eclipse有强大的编辑功能, 工欲善其事,必先利其器, 掌握Eclipse快捷键,可以大大提高工作效率. 编辑相关快捷键 注释 Ctrl + / 快速修复 Ctrl + ...
- ElasticSearch ik分词安装
1.下载对应版本的ES ik分词 https://github.com/medcl/elasticsearch-analysis-ik/releases 2.解压elasticsearch-analy ...