跳到正文

题解

AT_genocon2021_c Practice 3题解

#SUSPENDED#约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年4月26日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 2 分钟

版本

  1. v1当前

题目传送门
在这里食用风味更佳
这道题,初看非常难,但实际非常简单
那么 本蒟蒻要来水题解了!

分析题目

意思很简单,就是输入 mm 个字符串,通过添加 −- 将它们的末尾对齐 注意!填在哪里都没关系!所以我们都填在末尾!

思路点拨

思路1

那根据题目,我们就可以在输入时判断最长字符串的长度
然后储存下来
接着输出每个字符串,再补上 −- 这个字符

思路2

只要将末尾对齐…欸!我们是不是可以将每个字符串的长度都设为 10001000 !

代码分析

思路1

C++
#include <bits/stdc++.h>
using namespace std;
int m, mx/*最大长度*/;
string a[10005];
int main()
{
    cin >> m;//输入m
    for (int i = 1; i <= m; i++)
    {
        cin >> a[i];
        int l = a[i].length();
        mx = max(mx, l);//求最大长度
    }
    for (int i = 1; i <= m; i++)
    {
        cout << a[i];
        int l = a[i].length();
        for (int j = 1; j <= mx - l; j++)//补上缺失的-
            cout << "-";
        cout << endl;//注意换行!
    }
}

思路2

C++
#include <bits/stdc++.h>
using namespace std;
int m;
string a[10005];
int main()
{
    cin >> m;//输入m
    for (int i = 1; i <= m; i++)
        cin >> a[i];
    for (int i = 1; i <= m; i++)
    {
        cout << a[i];
        int l = a[i].length();
        for (int j = 1; j <= 1000 - l; j++)//补上1000 - l个-
            cout << "-";
        cout << endl;//注意换行!
    }
}
原文