字符串分隔(使用substr实现)
来源:互联网 发布:元数据和数据元区别 编辑:程序博客网 时间:2024/06/05 05:14
题目描述
连续输入字符串,请按长度为8拆分每个字符串后输出到新的字符串数组;
长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。
输入描述
连续输入字符串(输入2次,每个字符串长度小于100)
输出描述
输出到长度为8的新字符串数组
输入例子
abc
123456789
输出例子
abc00000
12345678
90000000
代码
#include<iostream> #include<string>using namespace std;void Output(string input) {//处理字符串输出格式的函数 int quotient = input.length() / 8;//计算行数 int reminder = input.length() % 8;//最后一行非0数 int count = 0; for (int i = 0; i < quotient; i++) { cout << input.substr(count, 8) << endl; count += 8; } if (reminder != 0) { cout << input.substr(count, reminder); for (int i = reminder; i < 8; i++) { cout << "0"; } cout << endl; }}int main() { string input1, input2; getline(cin, input1); getline(cin, input2); Output(input1); Output(input2); system("pause"); return 0;}
注释
substr()函数的作用是截取字符串的一段内容
声明格式:
substr(起始位置,长度)
str.substr(m,n)
0 0
- 字符串分隔(使用substr实现)
- substr 和 find函数实现自己的字符串分割函数(以指定分隔符分割字符串,分隔符可为字符串)
- 字符串分隔(java实现)
- c++实现字符串分隔
- python实现-字符串分隔
- 向数据库插入使用分隔符分隔(任意分隔符)的字符串脚本
- instr和substr对于分隔符号过滤使用
- 字符串水题(substr的使用+简单优化)
- oracle中实现截取字符串(substr)、查找字符串位置(instr)、替换字符串(replace)
- oracle中实现截取字符串(substr)、查找字符串位置(instr)、替换字符串(replace)
- oracle中实现截取字符串(substr)、查找字符串位置(instr)、替换字符串(replace)
- oracle中实现截取字符串(substr)、查找字符串位置(instr)、替换字符串(replace)
- substr()函数截取字符串
- 使用分隔符分割字符串
- 华为OJ(字符串分隔)
- js实现分隔字符串和freetextbox
- 实现任意分隔符的字符串提取
- oracle 拆分逗号分隔字符串 实现split
- struts2 spring mybatis整合
- iOS深入学习(Block全面分析)
- cocos2dx lua绑定
- 批处理命令findstr正则表达式的基本用法
- 图像特征提取:图像的矩特征
- 字符串分隔(使用substr实现)
- 【剑指offer-Java版】05从尾到头打印链表
- 装饰者模式
- 自动布局之masonry
- javascript冒泡事件的意义及如何阻止冒泡事件
- Elasticsearch的script使用
- 【Asp.Net】日期控件DatePicker使用
- HashMap中红黑树的查找函数find()实现
- C# 中的委托和事件