洛谷入门赛26部分题解

比赛链接:【LGR-196-Div.4】洛谷入门赛 #26 - 比赛详情 - 洛谷

 

A.相识于 2016

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	n=(n-2016)*12+(m-8+1);
	cout<<n;
	return 0;
}

B.游戏与共同语言

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n1,n2,n3,m1,m2,m3;
	cin>>n1>>n2>>n3>>m1>>m2>>m3;
	if(n1>m1)
	{
		cout<<"A";
		return 0;
	}
	else if(n1<m1)
	{
		cout<<"B";
		return 0;
	}
	else 
	{
		
		if(n2>m2)
		{
			cout<<"A";
			return 0;
		}
		else if(n2<m2)
		{
			cout<<"B";
			return 0;
		}
		else
		{
			
			if(n3>m3)
			{
				cout<<"B";
				return 0;
			}
			else if(n3<m3)
			{
				cout<<"A";
				return 0;
			}
		}
	}
}

C.皆与生物有缘

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i=0,j=0,m,k;
	cin>>n;
	k=n;
	while(k--)
	{
		cin>>m;
		i+=m;
	}
	while(n--)
	{
		cin>>m;
		j+=m;
	}
	n=(i+j)%2+(i+j)/2;
	cout<<n;
	return 0;
}

D. 两座城市的 543 千米

#include <iostream>
#include <vector>

using namespace std;

int main() {
    int N, M, a, b,c;
    cin >> N >> M >> a >> b;
    int count = 0;
    while (M--) 
    {
        int l;
        cin >> l;
        int foundA = -1;
        int foundB = -1;
        for (int i = 0; i < l; ++i) 
        {
            cin >> c;
            if(c==a&&foundA==-1)
            {
            	foundA=i;
			}
            if(c==b)
            {
            	foundB=i;
			}
        }
        if(foundA!=-1&&foundB!=-1&&foundA<foundB)
		{
			count++;
		 } 
    }

    cout << count << endl;
    return 0;
}

E.于抑郁中支持

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, t;
    cin >> n >> t;
    
    unordered_set<int> events;
    int mod = 1;
    for (int i = 0; i < t; ++i) {
        mod *= 10;  
    }

    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        int k = a % mod;
        events.insert(k);
    }

    cout << events.size() << endl;

    return 0;
}

F.蓝色的网易云

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, t, m;
    cin >> n >> t;
    int ssr[1000][n];
    map<int, int> num;
    for (int i = 1;i <= n;i++)
    {
        cin >> m;
        int o = num[m];
        ssr[m][o] = i;
        num[m]++;
    }
    for (int i = 1;i <= n / t;i++)
    {
        for (int j = 1;j <= t;j++)
        {
            cout << ssr[j][i - 1] << endl;
        }
    }
    return 0;
}

G.因友情而终结

#include <bits/stdc++.h>
using namespace std;
#define MAX_LENGTH 1000010
int solve(char *S) {
    int n = strlen(S);
    int operations = 0;
    for (int i = 0; i <= n - 6; ++i) {
        if (strncmp(S + i, "friend", 6) == 0) {
            strncpy(S + i + 5, "love", 4);
            ++operations;
        }
    }
    
    return operations;
}

int main() {
    char S[MAX_LENGTH];
    fgets(S, MAX_LENGTH, stdin);
    S[strcspn(S, "\n")] = '\0';
    cout<<solve(S);
    
    return 0;
}

  • 6
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值