题解 | #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;
}
相关推荐
ShineWinsu38 分钟前
对于C++:IO流状态的详细解析
c++·面试·io·cin·io流状态·goodbit·failbit
Lzg_na2 小时前
constexpr的优势
c++
王维同学3 小时前
进程模块枚举、映像身份与线程启动地址关联
c++·windows·安全
hold?fish:palm3 小时前
24 回文链表
数据结构·c++·链表
举手4 小时前
Dispatcher模块剖析
linux·c++
依然鸣5 小时前
PTA团体程序设计天梯赛L1真题讲解L1-077-080
开发语言·c++·算法·深度优先·pat考试·图论
库玛西6 小时前
现代 C++ 智能指针全景指南:从 RAII 思想到工业级实践
c语言·开发语言·c++·笔记·面试
liulilittle7 小时前
无锁并发容器的设计与实现原理
开发语言·c++·set·map·并发·无锁·lock-free
qeen877 小时前
【数据结构】自平衡二叉搜索树各种旋转算法原理解析及AVL树的C++实现
数据结构·c++·算法
Augustzero8 小时前
为什么线程不能说睡就睡?看懂等待与唤醒机制
c++·后端