模拟题刷题3

总结

stoi不能转char

栈模拟

时间显示保留前导0:printf("%02d:%02d", hour, second);

236A

简单

cpp 复制代码
void solve()
{
    unordered_map<char, int> map;
    string t;
    cin >> t;
    for (char c : t)
    {
        map[c]++;
    }
    if (map.size() % 2)
    {
        cout << "IGNORE HIM!";
    }
    else
    {
        cout << "CHAT WITH HER!";
    }
}

339A

注意stoi不能转char

cpp 复制代码
void solve()
{
    string t;
    cin >> t;
    vector<int> s;
    for (char c : t)
    {
        if (c != '+')
        {
            s.push_back(c - '0');
        }
    }
    sort(s.begin(), s.end());
    string ans = "";
    for (int n : s)
    {
        ans += to_string(n);
        ans += '+';
    }
    ans.pop_back();
    cout << ans;
}

281A

简单

cpp 复制代码
void solve()
{
    string t;
    cin >> t;
    if (t[0] >= 'a' && t[0] <= 'z')
    {
        t[0] = t[0] - 'a' + 'A';
    }
    cout << t;
}

791A

简单

cpp 复制代码
void solve()
{
    int a, b;
    cin >> a >> b;
    int ans = 0;
    while (a <= b)
    {
        ans++;
        a *= 3;
        b *= 2;
    }
    cout << ans;
}

266A

栈模拟

cpp 复制代码
void solve()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    stack<char> stk;
    for (char c : s)
    {
        if (!stk.empty() && stk.top() == c)
        {
            continue;
        }
        else
        {
            stk.push(c);
        }
    }
    cout << n - stk.size();
}

546A

简单

cpp 复制代码
void solve()
{
    int k, n, w;
    cin >> k >> n >> w;
    int sum = 0;
    for (int i = 1; i <= w; i++)
    {
        sum += i * k;
    }
    sum -= n;
    cout << max(sum, 0);
}

1133A

时间显示保留前导0:printf("%02d:%02d", hour, second);

cpp 复制代码
void solve()
{
    string a, b;
    cin >> a >> b;
    int x = stoi(a.substr(0, 2)) * 60 + stoi(a.substr(3, 2));
    int y = stoi(b.substr(0, 2)) * 60 + stoi(b.substr(3, 2));
    int time = (y - x) / 2;
    int hour = stoi(a.substr(0, 2)) + time / 60;
    time %= 60;
    int second = stoi(a.substr(3, 2)) + time;
    if (second >= 60)
    {
        int k = second / 60;
        hour += k;
        second = second - k * 60;
    }
    printf("%02d:%02d", hour, second);
}

441A

注意读完数据,没有读完就break会导致本次读入上一次的数据

cpp 复制代码
void solve()
{
    vector<int> ans;
    int n, v;
    cin >> n >> v;
    for (int i = 1; i <= n; ++i)
    {
        int k;
        cin >> k;
        bool ok = false;
        for (int j = 0; j < k; ++j)
        {
            int t;
            cin >> t;
            if (t < v)
                ok = true; // 只标记,不 break
        }
        if (ok)
            ans.push_back(i);
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
    {
        cout << ans[i] << " ";
    }
}
相关推荐
JieE2121 天前
LeetCode 226. 翻转二叉树|JS 递归超详细拆解,二叉树入门经典题
javascript·算法
JieE2121 天前
LeetCode 104. 二叉树的最大深度|递归思路超详细拆解
javascript·算法
用户3521802454751 天前
当 Prompt 学会"热更新":Spring Boot × Nacos3 AI 实战
java·spring boot·ai编程
vivo互联网技术1 天前
CVPR 2026 | 全新强化学习框架 BeautyGRPO:重塑真实人像
算法·大模型·cvpr·影像
Darling噜啦啦1 天前
列表转树算法深度解析:从 Map 到 Reduce 的两种实现,面试高频考点
数据结构·算法·面试
东坡白菜1 天前
破局全栈:一个前端开发的Java入门实战记录(1)
java·全栈
唐青枫1 天前
Java Tomcat 实战指南:从 Servlet 容器到 Spring Boot 部署
java
wsaaaqqq1 天前
roudan:自由选择实体、灵活操作数据、快速写入数据库的 Java 框架
java
用户497863050731 天前
(一)小红的数组操作
算法·编程语言