蓝桥杯(C++)--语言基础

本文介绍了C++编程中的几个基础示例,包括使用if语句实现的反转游戏、检查日期是否为顺子的函数以及解决小明和完美序列的问题。涉及了STL库和基本数据结构的使用。
摘要由CSDN通过智能技术生成

编程基础

1.妮妮的反转游戏

#include<iostream>
using namespace std;

int main(){
    int x;
    cin>>x;
    if(x==0)cout<<1<<"\n";
    if(x==1)cout<<0<<"\n";
    return 0;
}

输入向右

常用库函数

STL

2.顺子日期,不建议看

#include<bits/stdc++.h>  
using namespace std;
const int N=1e5+7;
int month[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int main(){
	int ans=0;
	for(int i=0;i<2;i++)
		for(int j=0;j<10;j++){
			int k=j+1;
			for(int l=0;l<10;l++){
				int m=i*10+j;
				int d=k*10+l;
				if(m<13&&d<=month[m]&&(i==j-1||k==l-1)) 
				cout<<m<<" "<<d<<endl;
				ans++;
			}
		}
	cout<<ans<<endl;
	return 0;
	
}

这题纯****,别试了

3.小明和完美序列  OJ:3199

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;

signed main()
{
    int n; cin >> n;
    vector<int> a(n + 1);
    map<int, int> cnt;
    for(int i = 1; i <= n; i ++) {
        cin >> a[i];
        cnt[a[i]] ++;
    }
    int ans = 0;
    for(auto [x, y] : cnt) {
        if(y > x) ans += y - x;
        else if(y < x) ans += y;
    }
    cout << ans;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值