当前位置:网站首页>输入不定长数组,输入一个字符串,既包含字符,又包含数字,输出数组,输入一个二维数组,字符和数字都可
输入不定长数组,输入一个字符串,既包含字符,又包含数字,输出数组,输入一个二维数组,字符和数字都可
2022-08-09 14:59:00 【李昊19961128】
//输入不定长数组,输入一个字符串,既包含字符,又包含数字,输出数组,输入一个二维数组,字符和数字都可
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;
void test01() //输入一个字符串,既包含字符,又包含数字,输出数组
{
string str;
cin >> str;
int sum = 0;
vector<int> v;
for (int i = 0; i <= str.size(); i++)
{
if (str[i] >= '0' && str[i] <= '9')
{
sum = sum * 10 + str[i] - 48;
}
else
{
if (sum)
{
v.push_back(sum);
}
sum = 0;
}
}
for (int i = 0; i < v.size(); i++)
{
cout << v[i] << " ";
}
cout << endl;
}
void test02() //输入一个二维数组,字符和数字都可
{
vector<vector<char>> arr;
vector<char> v;
int m;
int n;
cin >> m >> n;
cout << endl;
for (int i = 0; i < m; i++)
{
v.clear();
for (int j = 0; j < n; j++)
{
char tmp;
cin >> tmp;
v.push_back(tmp);
}
arr.push_back(v);
}
for (int i = 0; i < arr.size(); i++)
{
for (int j = 0; j < arr[0].size(); j++)
{
cout << arr[i][j] << " ";
}
cout << endl;
}
cout << endl;
}
void test03() //输入不定长数组
{
vector<int> v;
do
{
int tmp;
cin >> tmp;
v.push_back(tmp);
} while (getchar() != '\n');
for (int i = 0; i < v.size(); i++)
{
cout << v[i] << " ";
}
cout << endl;
}
int main()
{
//test01();
//test02();
//test03();
system("pause");
return 0;
}
边栏推荐
猜你喜欢

Face recognition sample code analysis (2) - face recognition analysis

【力扣】98. 验证二叉搜索树

【学习笔记】win10报0xc0000221错误无法开机

Vim实用技巧_5.在文件间和文件内快速移动

深入浅出最优化(2) 步长的计算方法

Stetman读peper小记:Defense-Resistant Backdoor Attacks Against DeepNeural Networks in Outsourced Cloud

Vim实用技巧_3.可视模式和命令模式

图解转置卷积原理

The experience of using Photoshop CS6

Virtualbox 设置共享文件夹
随机推荐
【力扣】617. 合并二叉树
Correlation analysis
杭州富阳科目三新规3号线考试攻略
【SQL】595. 大的国家
【力扣】1995. 统计特殊四元组
深入浅出最优化(3) 最速下降法与牛顿法
时间序列分析
UDP 基本通信框架
Word 2016 撰写论文(1): 公式居中、编号右对齐
[Deep learning] attention mechanism
PE format series _0x05: output table and relocation table (.reloc)
hugging face tutorial - Chinese translation - sharing custom model
【Likou】1995. Statistical special quadruple
灰色关联度矩阵——MATLAB在数学建模中的应用
Vitis部分实验记录
流体拓扑优化问题
Gray Relevance Matrix——Application of MATLAB in Mathematical Modeling
【工具使用】Modbus Slave软件使用详解
堆(heap)系列_0x09:堆破坏示例(非法访问+未初始化+堆句柄不匹配)
Vim实用技巧_7.模式匹配和查找