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小时才做到这

相关推荐
Duck Bro25 分钟前
MySQL:常用数据类型
java·数据库·c++·mysql·java-ee
z千鑫26 分钟前
【C/C++】数据库链接入门教程:从零开始的详细指南!MySQL集成与操作
c语言·数据库·c++
kitesxian33 分钟前
Leetcode53. 最大子数组和(HOT100)
数据结构·算法·leetcode
重生之我在VS写bug3 小时前
【C++知识总结2】C++里面的小配角cout和cin
数据结构·c++·算法
HUT_Tyne2653 小时前
力扣--LCR 141.训练计划III
算法·leetcode·职场和发展
pzn25064 小时前
蓝桥杯练习题
c++·算法·蓝桥杯
Zafir20244 小时前
Qt实现窗口内的控件自适应窗口大小
c++·qt·ui
捕鲸叉4 小时前
C++设计模式之组合模式中适用缓存机制提高遍历与查找速度
c++·设计模式·组合模式
奶茶戒断高手4 小时前
【CSP CCF记录】201903-2第16次认证 二十四点
数据结构·c++·算法
xxxmmc5 小时前
Leetcode 290 word Pattern
算法·leetcode·hashmap双映射