行程编码(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 ...
随机推荐
- sqL编程篇(三) 游标与存储过程
sql编程2 游标与存储过程 sql编程中的游标的使用:提供的一种对查询的结果集进行逐行处理的一种方式不用游标的处理解决方式:逐行修改工资update salar set 工资=‘新工资’ where ...
- 下载判断Android和iOS
//下载 function down(){ var url = ''; var u = navigator.userAgent, app = navigator.appVersion; var isA ...
- 浏览器访问Servlet
浏览器访问Servlet1.指定一个Servlet路径( 在web.xml : <servlet> ...
- ABP理论学习之OWIN集成
返回总目录 如果你的应用中使用了OWIN,那么需要在主项目(一般来说是指Web项目)中添加Abp.Owin的nuget包,然后像下面那样在OWIN的 Startup文件中调用 UseAbp()扩展方法 ...
- ASP.NET MVC 5 - 查询Details和Delete方法
在这部分教程中,接下来我们将讨论自动生成的Details和Delete方法. 查询Details和Delete方法 打开Movie控制器并查看Details方法. public ActionResul ...
- 【VC++技术杂谈007】使用GDI+进行图片格式转换
本文主要介绍如何使用GDI+对图片进行格式转换,可以转换的图片格式为bmp.jpg.png. 1.加载GDI+库 GDI+是GDI图形库的一个增强版本,提供了一系列Visual C++ API.为了使 ...
- Android开发学习之路-让注解帮你简化代码,彻底抛弃findViewById
本文主要是记录注解的使用的学习笔记,如有错误请提出. 在通常的情况下,我们在Activity中有一个View,我们要获得这个View的实例是要通过findViewById这个方法,然后这个方法返回的是 ...
- JS面向对象(2) -- this的使用,对象之间的赋值,for...in语句,delete使用,成员方法,json对象的使用,prototype的使用,原型继承与原型链
相关链接: JS面向对象(1) -- 简介,入门,系统常用类,自定义类,constructor,typeof,instanceof,对象在内存中的表现形式 JS面向对象(2) -- this的使用,对 ...
- ATM模拟器(附代码及运行结果)
源代码: import java.util.Scanner; class Account{ String identify; String name; String date; String key; ...
- dd
1.属性 关键:get,set public class Account { private string id; private decimal money; public string Id { ...