贴贴 官方题解

· · 题解

这里是官方题解。

简单模拟题。

首先输出无论如何都要输出的 solution-,然后枚举题号的每个字符 c:如果 c 是大写字母,就转为小写字母输出;如果 c 是下划线,就输出减号;否则,原样输出即可。

时间复杂度 O(|s|)。

// Problem: T361845 贴贴
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/T361845
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//By: OIer rui_er
#include <bits/stdc++.h>
#define rep(x,y,z) for(int x=(y);x<=(z);x++)
#define per(x,y,z) for(int x=(y);x>=(z);x--)
#define debug(format...) fprintf(stderr, format)
#define fileIO(s) do{freopen(s".in","r",stdin);freopen(s".out","w",stdout);}while(false)
using namespace std;
typedef long long ll;

mt19937 rnd(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
int randint(int L, int R) {
    uniform_int_distribution<int> dist(L, R);
    return dist(rnd);
}

template<typename T> void chkmin(T& x, T y) {if(x > y) x = y;}
template<typename T> void chkmax(T& x, T y) {if(x < y) x = y;}

int main() {
    string s;
    cin >> s;
    printf("solution-");
    for(char c : s) {
        if(isupper(c)) putchar(tolower(c));
        else if(c == '_') putchar('-');
        else putchar(c);
    }
    return 0;
}