当前位置:网站首页>输入不定长数组,输入一个字符串,既包含字符,又包含数字,输出数组,输入一个二维数组,字符和数字都可
输入不定长数组,输入一个字符串,既包含字符,又包含数字,输出数组,输入一个二维数组,字符和数字都可
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;
}
边栏推荐
猜你喜欢
随机推荐
深入浅出最优化(4) 拟牛顿法
图像质量指标:峰值信噪比PSNR和结构相似性SSIM
Candide3 face animation model
CTF online encryption and decryption and common tools
杭州富阳科目三新规3号线考试攻略
Matlab做分布拟合及绘制频率分布直方图
Face recognition sample code analysis (2) - face recognition analysis
灰色关联分析
【Postgraduate Work Weekly】(Week 9)
【力扣】17. 电话号码的字母组合
相关性分析
交叉编译 Crypto++
图论最短路径求解
【Postgraduate Work Weekly】(The third week)
R-CNN Fast R-CNN Faster R-CNN总结
The experience of using Photoshop CS6
ConvNext笔记
Introduction to common commands in SQLMap
堆(heap)系列_0x0A:3种方法一次性解决堆溢出问题
前置后置运算符重载









