题解 | #1005.List Reshape# 2023杭电暑期多校9

1005.List Reshape

签到题

题目大意

按一定格式给定一个纯数字一维数组,按给定格式输出成二维数组。

解题思路

读入初始数组字符串,将每个数字分离,按要求输出即可

参考代码

参考代码为已AC代码主干,其中部分功能需读者自行实现

cpp{.line-numbers} 复制代码
#define N 100005
char s[N]={0};
vector<string> nums;
void getnums(){
    string ts;ll len=strlen(s);char c;
    FORLL(i,0,len){
        c=s[i];
        if(c>='0'&&c<='9') ts.push_back(c);
        else if(ts.size()){
            nums.emplace_back(ts);
            ts.clear();
        }
    }
}
void solve()
{
    getchar();gets(s);
    ll n,m;scanf("%lld%lld",&n,&m);
    nums.clear();getnums();
    //print_vec(nums);
    cout << '[';
    FORLL(i,0,n-1){
        cout << '[';
        FORLL(j,0,m-1){
            cout << nums[i*m+j];
            if(m-1-j) cout << ", ";
        }cout << "]";
        if(n-1-i) cout << ", ";
    }cout << ']' << endl;
}
相关推荐
无忧.芙桃6 小时前
C++语言原理与实践(二十三):哈希表的实现
c++·链表·哈希算法·散列表·哈希表
AvocadoZeroOneOI9 小时前
B4500 [GESP202603 三级] 凯撒密码 详细解题报告
c++·算法
whitelbwwww11 小时前
cuBLAS--CUDA高性能线性代数计算库--第一部分
c++·线性代数·gpu算力·cuda c++
eggwyw14 小时前
C++设计模式之解释器模式
开发语言·c++
我不会插花弄玉1 天前
13.多路转接epoll【由浅入深-网络】
网络·c++·epoll
郝学胜-神的一滴1 天前
Effective STL 条款03:容器中的对象复制要廉价且正确
开发语言·数据结构·c++·算法·rpc·stl
西西弗Sisyphus1 天前
C++ explicit 关键字工程实践
开发语言·c++
AIgorithmGEEK1 天前
std::unordered_map 与 std::unordered_set:接口、算法技巧与权衡 (速查)
c++·算法·哈希表·负载因子·桶·unordered_map·unordered_set
一拳一个呆瓜1 天前
【STL】头文件:<cmath>
c++·stl
草莓熊Lotso1 天前
【C++ 基于微服务的即时通讯系统】ElasticSearch 用户数据管理实现
linux·数据库·c++·elasticsearch·微服务·架构