A题 首字母大写

签到题

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#define IOS ios::sync_with_stdio(false)
#define CC cin.tie(nullptr),cout.tie(nullptr)
#define ll long long
#define f first
#define s second

using namespace std;

typedef pair<int ,int> PII;
typedef double D;
const int N = 100010, M = 1e5 + 10;

int idx,e[N],l[N],r[N];

void solve() {
    string s;
    cin >> s;
    if (s[0] >= 'a' && s[0] <= 'z')s[0] = s[0] - 32;
    cout << s;
}

int main() {
    IOS;
    CC;
    int h_h = 1;
    //cin >> h_h;
    while (h_h--) solve();
    return 0;
}

也可以直接使用函数toupper

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#define IOS ios::sync_with_stdio(false)
#define CC cin.tie(nullptr),cout.tie(nullptr)
#define ll long long
#define f first
#define s second

using namespace std;

typedef pair<int ,int> PII;
typedef double D;
const int N = 100010, M = 1e5 + 10;

int idx,e[N],l[N],r[N];

void solve() {
    string s;
    cin >> s;
    s[0]=toupper(s[0]);
    cout << s;
}

int main() {
    IOS;
    CC;
    int h_h = 1;
    //cin >> h_h;
    while (h_h--) solve();
    return 0;
}

B题

考察贪心,最大的数肯定是从高位开始填每位都是9,不足9就填能填的,最小的数从低位开始,要保证最高位为1,每位填9,不足9能填多少填多少,还要特判无解的情况,给出位数乘以9还比给出的和要小或者给出的位数为零并且总和大于1

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#define IOS ios::sync_with_stdio(false)
#define CC cin.tie(nullptr),cout.tie(nullptr)
#define ll long long
#define f first
#define s second

using namespace std;

typedef pair<int ,int> PII;
typedef double D;
const int N = 100010, M = 1e5 + 10;

void solve() {
    int m, s;
    cin >> m >> s;
    if (m * 9 < s || s == 0 && m > 1)cout << "-1 -1" << endl;
    else if (m == 1 && s == 0)cout << "0 0" << endl;
    else {
        string mn(m, '-'), mx(m, '-');
        int sum = s;
        for (int i = m - 1; i; i--) {
            int t = min(9, sum - 1);
            if (sum - 1 < 9)sum -= sum - 1;
            mn[i] = t + '0';
            if (sum - 9 < 0) {
                for (int j = i - 1; j >= 1; j--)mn[j] = '0';
                break;
            }
            sum -= 9;

        }
        mn[0] = (sum) + '0';
        for (int i = 0; i < m; i++) {
            int t = min(9, s);
            mx[i] = t + '0';
            if (s - 9 < 0) {
                for (int j = i + 1; j < m; j++)mx[j] = '0';
                break;
            }
            s -= 9;
        }
        //mx[m - 1] = s + '0';
        cout << mn << ' ' << mx << endl;
    }
}

int main() {
    IOS;
    CC;
    int h_h = 1;
    //cin >> h_h;
    while (h_h--) solve();
    return 0;
}

但是好像y总的写法更简单,每次都减,减到零以后后面的一直填零

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    int m, s;
    cin >> m >> s;
    if (s > m * 9 || !s && m > 1) puts("-1 -1");
    else
    {
        string a(m, ' '), b(m, ' ');
        int sum = s;
        for (int i = m - 1; i; i -- )
        {
            int t = min(9, sum - 1);
            a[i] = t + '0';
            sum -= t;
        }
        a[0] = sum + '0';
        sum = s;
        for (int i = 0; i < m; i ++ )
        {
            int t = min(9, sum);
            b[i] = t + '0';
            sum -= t;
        }
        cout << a << ' ' << b << endl;
    }

    return 0;
}

C题 构造字符串

使用KMP算法寻找最大的公共前后缀,然后先输出给出字符串,接着按照题意输出多少个后缀就可以了。

#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

const int N=55;

int n,t;
char s[N];
int ne[N];

int main() {
    cin >> n >> t >> s + 1;
    for (int i = 2, j = 0; i <= n; i++) {
        while (j && s[i] != s[j + 1])j = ne[j];
        if (s[i] == s[j + 1])j++;
        ne[i] = j;
    }
    cout << s + 1;
    for (int i = 0; i < t - 1; i++) {
        cout << s + 1 + ne[n];
    }
    return 0;
}