题解 | #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;
}
相关推荐
端平入洛3 小时前
delete又未完全delete
c++
端平入洛1 天前
auto有时不auto
c++
哇哈哈20212 天前
信号量和信号
linux·c++
多恩Stone2 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
蜡笔小马2 天前
21.Boost.Geometry disjoint、distance、envelope、equals、expand和for_each算法接口详解
c++·算法·boost
超级大福宝2 天前
N皇后问题:经典回溯算法的一些分析
数据结构·c++·算法·leetcode
weiabc2 天前
printf(“%lf“, ys) 和 cout << ys 输出的浮点数格式存在细微差异
数据结构·c++·算法
问好眼2 天前
《算法竞赛进阶指南》0x01 位运算-3.64位整数乘法
c++·算法·位运算·信息学奥赛
yyjtx2 天前
DHU上机打卡D31
开发语言·c++·算法
czxyvX2 天前
020-C++之unordered容器
数据结构·c++