2023天梯赛

L1-1

cpp 复制代码
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#define x first
#define y second
using namespace std;
using LL = long long;

typedef pair<int, int> PII;


void solve()
{
	cout << "Good code is its own best documentation." << endl;
}

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int _ = 1;
	while (_--) solve();
	return 0;
}

L1-2

cpp 复制代码
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#define x first
#define y second
using namespace std;
using LL = long long;

typedef pair<int, int> PII;

int a, b;

void solve()
{
	cin >> a >> b;
	cout << a + b - 16 << endl;
	cout << a + b - 3 << endl;
	cout << a + b - 1 << endl;
	cout << a + b << endl;
}

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int _ = 1;
	while (_--) solve();
	return 0;
}

L1-3

cpp 复制代码
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#define x first
#define y second
using namespace std;
using LL = long long;

typedef pair<int, int> PII;

int n, m, k;
string x;

void solve()
{
	cin >> n >> x >> m >> k;
	if (k == n) cout << "mei you mai " << x << " de" << endl;
	else if (k == m) cout << "kan dao le mai " << x << " de" << endl;
	else cout << "wang le zhao mai " << x << " de" << endl;
}

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int _ = 1;
	while (_--) solve();
	return 0;
}

L1-4

cpp 复制代码
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#define x first
#define y second
using namespace std;
using LL = long long;

typedef pair<int, int> PII;

int n;
    
void solve()
{
    cin >> n;
    while(n--)
    {
        int a,b,c;
        cin >> a >> b >> c; 
        if (c == a * b) cout << "Lv Yan" << endl;
        else if (c == a + b) cout << "Tu Dou" << endl;
        else cout << "zhe du shi sha ya!" << endl;
    }
}

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int _ = 1;
	while (_--) solve();
	return 0;
}

L1-5

cpp 复制代码
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#define x first
#define y second
using namespace std;
using LL = long long;

typedef pair<int, int> PII;

const int N = 110;

int n,m;
int a[N];
    
void solve()
{   
    cin >> n;
    for (int i = 1;i <= n;i++)
    cin >> a[i];
    cin >> m;
    while(m--)
    {
        bool all_no = false;
        bool wrong = false;
        bool no_win =false;
        for (int i = 1;i <= n;i++)
        {
            int x;
            cin >> x;
            if (x == a[i])
            {
                all_no = true;
             no_win = true;
            }
            if (x + a[i] == 3)
            {
                wrong = true;
                all_no = true;
            }
        }
        if (wrong == false && no_win) cout << "Da Jiang!!!" << endl;
        if (!all_no || wrong) cout << "Ai Ya" << endl;
    }
    
}

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int _ = 1;
	while (_--) solve();
	return 0;
}

L1-6 (寄了)

s.substr(a,b),a是所截取的子串在原始字符串的起始位置,而b则是截取长度,不是子串的终止位置!

cpp 复制代码
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#define x first
#define y second
using namespace std;
using LL = long long;

typedef pair<int, int> PII;

const int N = 210;

string s;
string tp[N];
int n;
int a,b;
string s1,s2;
void solve()
{   
    cin >> s;
    cin >> n;
    for (int i = 1;i <= n;i++)
    {
        cin >> a >> b >> s1 >> s2;
        tp[i] = s.substr(a - 1,b - 1);
        s.erase(a - 1,b - 1); // 删除与截取一样[]
        int st = s.find(s1);
        int ed = s.find(s2);        
        // cout << st << endl;
        // cout << ed << endl;
        
        // cout << s << endl;
        // s.insert((st + ed) / 2 + 1,tp[i]);
        // cout << s << endl;

        if (st == -1) //找不到返回-1
        {
            s.insert(s.size(),tp[i]); //在下标为s.size()处插入
            // cout << s << endl;
        }
        else
        {
            
            s.insert((st + ed) / 2 + 1,tp[i]);
        }
    }
    cout << s << endl;
}

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int _ = 1;
	while (_--) solve();
	return 0;
}

改正后

cpp 复制代码
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <vector>
#define x first
#define y second
using namespace std;
using LL = long long;

typedef pair<int, int> PII;

const int N = 210;

string s;
int n;
int a,b;
string s1,s2;
void solve()
{   
    cin >> s;
    cin >> n;
    while(n--)
    {
        cin >> a >> b >> s1 >> s2;
        string s3 = s.substr(a - 1,b - a + 1);  //开始下标,长度
        s.erase(s.begin() + a - 1,s.begin() + b); // 删除[)
		int len = s1.length();
		string tmp = s1 + s2;
        int pos = s.find(tmp);
		if(pos != s.npos) s.insert(pos + len, s3); // 从下标pos + len 处插入 s3
		else s.insert(s.length(), s3);

    }
    cout << s << endl;
}

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int _ = 1;
	while (_--) solve();
	return 0;
}

L1-7 19分(wa了1分)

cpp 复制代码
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#define x first
#define y second
using namespace std;
using LL = long long;

typedef pair<int, int> PII;

const int N = 100010;

int n,m,s;
vector <int> a;
vector <int> b;
// map<int,PII> mp;
void solve()
{   
    cin >> n >> m>> s;

    for (int i = 1;i <= n / i;i++)
    {
        if (n % i) continue;
        a.push_back(i);
        if (i != n / i) a.push_back(n / i);
    }
    
    sort(a.begin(),a.end());
    a.erase(unique(a.begin(),a.end()),a.end());
    // for (auto&t : a)
    // cout << t << " ";
    // cout << endl;
    
    for (int i = 1;i <= m / i;i++)
    {
        if (m % i) continue;
        b.push_back(i);
        if (i != m / i) b.push_back(m / i);
    }
    
    sort(b.begin(),b.end());
    b.erase(unique(b.begin(),b.end()),b.end());
    // for (auto&t : b)
    // cout << t << " ";
    // cout << endl;
    
    int minn = 1e9;
    int tp1 = -1,tp2 = -1;
   for (int i = 0;i < a.size();i++)
       for (int j = 0;j < b.size();j++)
       {
           if ((n / a[i] + m / b[j]) == s) 
           {
               if (abs(a[i] - b[j]) < minn) 
               {
                   minn = abs(a[i] - b[j]);
                   tp1 = n / a[i],tp2 = m / b[j];
               }
            //   mp[abs(a[i] - b[j])] = {a[i],b[j]};
            //   printf("%d %d %d %d\n",a[i],n / a[i],b[j],m / b[j]);
           }
       }
       if (tp1 == -1 && tp2 == -1) cout << "No Solution" << endl;
       else 
       cout << tp1 << " " << tp2 << endl;
}

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int _ = 1;
	while (_--) solve();
	return 0;
}

3小时才做到这

相关推荐
霁月风28 分钟前
设计模式——适配器模式
c++·适配器模式
sp_fyf_202429 分钟前
计算机前沿技术-人工智能算法-大语言模型-最新研究进展-2024-11-01
人工智能·深度学习·神经网络·算法·机器学习·语言模型·数据挖掘
香菜大丸1 小时前
链表的归并排序
数据结构·算法·链表
jrrz08281 小时前
LeetCode 热题100(七)【链表】(1)
数据结构·c++·算法·leetcode·链表
oliveira-time1 小时前
golang学习2
算法
咖啡里的茶i1 小时前
Vehicle友元Date多态Sedan和Truck
c++
海绵波波1071 小时前
Webserver(4.9)本地套接字的通信
c++
@小博的博客1 小时前
C++初阶学习第十弹——深入讲解vector的迭代器失效
数据结构·c++·学习
南宫生2 小时前
贪心算法习题其四【力扣】【算法学习day.21】
学习·算法·leetcode·链表·贪心算法
爱吃喵的鲤鱼2 小时前
linux进程的状态之环境变量
linux·运维·服务器·开发语言·c++