牛客周赛部分题解

比赛地址:牛客竞赛_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ

A.小红的对错判断

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long  
#define ull unsigned long long

void solve() {
    string ssr;
    cin>>ssr;
    int a=ssr.length();
    if(a==3)
    {
        if(ssr[0]=='y'||ssr[0]=='Y')
        {
            if(ssr[1]=='e'||ssr[1]=='E')
            {
                if(ssr[2]=='s'||ssr[2]=='S')
                {
                    cout<<"accept"<<endl;
                    return;
                }
            }
        }
    }
    cout<<"wrong answer"<<endl;
} 

signed main() {
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);

    ll t = 1; 
    // std::cin >> t;
    while (t--) {
        solve();
    }
}

B.小红的幂表达

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int x;
    cin >> x;
    cout << x << endl;
    cout<<"="<<x<<"^1"<<endl;
    for(int i=sqrt(x);i>=2;i--)
    {
        int sum=0;
        int j=x;
        while(1)
        {
            if(j%i==0)
            {
                j/=i;
                sum++;
                if(j==1)
                {
                    cout<<"="<<i<<"^"<<sum<<endl;
                    break;
                }
            }
            else
            {
                break;
            }
        }
    }

    return 0;
}

C.小红的前缀询问

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<long long int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    unordered_map<long long int, int> ssr;
    long long int pairCount = 0;
    vector<long long int> result(n);

    for (int i = 0; i < n; ++i) {
        ssr[a[i]]++;
        int newPairs = ssr[a[i]] - 1;
        pairCount += newPairs;
        result[i] = pairCount;
    }
    for (int i = 0; i < n-1; ++i) {
        cout << result[i] <<" ";
    }
    cout << result[n-1];
    return 0;
}

D.红和小紫的博弈游戏

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

void solve() {
    long long int a, b, c, d;
    cin >> a >> b >> c >> d;
    long long int totalSum = a + b + c + d;
    if (totalSum == 0||totalSum==1) 
    {
        cout << "yukari" << endl;
        return;
    }
    int x=a+d;
    int y=b+c;
    x=min(x,y);
    if(x%2)
    {
        cout << "kou" << endl;
    }
    else
    {
        cout << "yukari" << endl;
    }
    
    
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}
相关推荐
攻城狮7号21 分钟前
【第48节】探究汇编使用特性:从基础到混合编程
汇编·c++·windows
溟洵26 分钟前
【Qt】控件的理解 和 基础控件 QWidget 属性详解(通俗易懂+附源码+思维导图框架)
c语言·开发语言·前端·c++·windows·qt
Dovis(誓平步青云)30 分钟前
【数据结构】励志大厂版·初级(二刷复习)双链表
c语言·数据结构·经验分享·笔记·学习·算法·学习方法
YuforiaCode33 分钟前
第十四届蓝桥杯 2023 C/C++组 日期统计
c语言·c++·蓝桥杯
Zfox_33 分钟前
【Qt】QDialog类
c++·qt·qt5·客户端开发
共享家952744 分钟前
刷题之路:C++ 解题分享与技术总结
c++·leetcode
维维宝宝最可爱啦QWQ2 小时前
深入解析C++ STL List:双向链表的特性与高级操作
c++·链表·list
姜行运2 小时前
每日算法【双指针算法】(Day 2-复写零)
c++·算法·c#
伊H5 小时前
C语言main的参数;argc与argv
linux·c语言·算法
triticale5 小时前
【数论】快速幂
java·算法