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

相关推荐
jiao000012 小时前
数据结构——队列
c语言·数据结构·算法
迷迭所归处3 小时前
C++ —— 关于vector
开发语言·c++·算法
leon6253 小时前
优化算法(一)—遗传算法(Genetic Algorithm)附MATLAB程序
开发语言·算法·matlab
CV工程师小林3 小时前
【算法】BFS 系列之边权为 1 的最短路问题
数据结构·c++·算法·leetcode·宽度优先
Navigator_Z4 小时前
数据结构C //线性表(链表)ADT结构及相关函数
c语言·数据结构·算法·链表
Aic山鱼4 小时前
【如何高效学习数据结构:构建编程的坚实基石】
数据结构·学习·算法
white__ice4 小时前
2024.9.19
c++
天玑y4 小时前
算法设计与分析(背包问题
c++·经验分享·笔记·学习·算法·leetcode·蓝桥杯
姜太公钓鲸2334 小时前
c++ static(详解)
开发语言·c++
菜菜想进步4 小时前
内存管理(C++版)
c语言·开发语言·c++