1.蓝桥杯
日期问题
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<set>
using namespace std;
struct data
{
int year,month,day;
bool operator < (const data &A) const//重载运算符'<'
{//排序
if(A.year!=year)
return A.year>year;
else if(A.month!=month)
return A.month>month;
else return A.day>day;
}
};
set<data> s;
int leap_year(int year)//判断平闰年
{
if(year%4==0&&year%100!=0||year%400==0)
return 1;
else
return 0;
}
int check(int year,int month,int day)//判断是否符合条件
{
int leap[13]= {0,31,29,31,30,31,30,31,31,30,31,30,31};
int nonleap[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31};
if(month>12||month<1)//月份不符合
return 1;
if(leap_year(year)&&leap[month]<day||day==0)//是闰年该月的天数不符合
return 1;
if(!leap_year(year)&&nonleap[month]<day||day==0)//不是闰年天数不符合
return 1;
return 0;
}
void scanf_data(int year,int month,int day)//将符合条件的放入容器内
{
if(year>60)
year+=1900;
else
year+=2000;
if(check(year,month,day))
return ;
data P;
P.year=year;
P.month=month;
P.day=day;
s.insert(P);
}
int main()
{
int a,b,c;
scanf("%d/%d/%d",&a,&b,&c);
//三种情况
scanf_data(a,b,c);
scanf_data(c,a,b);
scanf_data(c,b,a);
//输出
set<data>::iterator it;
for(it=s.begin();it!=s.end();it++)
printf("%d-%02d-%02d\n",(*it).year,(*it).month,(*it).day);
}
包子凑数
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
#define ms(x, n) memset(x,n,sizeof(x));
typedef long long LL;
const int inf = 1<<30;
const LL maxn = 110;
int N, a[maxn], maxN = 0;
bool is[maxn*maxn];
void Dfs(int i, int n){
//当前选第i个, 总和n
is[n] = true;
for(int j = 1; j <= N; j++)
if(!is[n+a[j]] && n+a[j]<=maxN)
Dfs(j, n+a[j]);
}
int solve(){
ms(is, 0);
maxN *= maxN;
for(int i = 1; i <= N; i++)
if(!is[a[i]] && a[i]<=maxN)
Dfs(i, a[i]);
int ret = 0;
for(int i = 1; i < maxN; i++){
if(!is[i] && i>a[1]*a[N]) return -1; //超出这个范围依然有取不到的可以认为是INF
if(!is[i]) ret++;
}
return ret;
}
int main()
{
cin >> N;
bool even = true, odd = true;
for(int i = 1; i <= N; i++){
cin >> a[i];
maxN = max(a[i], maxN);
if(a[i]%2==0) odd = false;
else if(a[i]%2!=0) even = false;
}
//是否都是奇数/偶数
int ans = solve();
if(even || odd || ans==-1) cout << "INF" << endl;
else cout << ans << endl;
return 0;
}
2.寒假训练
吐泡泡
#include<stack>
#include<cstring>
#include<iostream>
using namespace std;
#define clean(a,b) memset(a,b,sizeof(a))// 雷打不动的头文件
char chuan[105];
char can[105];
int main()
{
while(~scanf("%s",&chuan)) //输进去所有的泡泡
{
stack<char> zhan; //定义一个栈
int i,j,l=strlen(chuan); //取长度
for(i=0;i<l;++i)
{
if(zhan.size()==0) //如果栈为空,就直接放进去
{
zhan.push(chuan[i]);
continue; //跳过循环
}
if(zhan.top()=='O'&&chuan[i]=='O') //爆炸的情况
{
zhan.pop(); //就踢出去一个栈顶元素
continue; //跳出循环
}
if(zhan.top()=='o'&&chuan[i]=='o') //合二为一的情况
{
zhan.pop(); // 先去掉栈顶元素
if(zhan.size()) //如果 此时还有元素
{
if(zhan.top()=='O') //&&栈顶可消
zhan.pop(); //再消一个
}
else // 没元素了
zhan.push('O'); //把大泡泡放进去
continue; //跳出循环
}
zhan.push(chuan[i]); //如果上述条件都不符合(一个小泡泡+大泡泡)
}
while(zhan.size()) //将栈内元素放到字符串内
{
can[zhan.size()-1]=zhan.top();
zhan.pop();
}
l=strlen(can); //取长度
for(i=0;i<l;++i)
printf("%c",can[i]); //输出格式
printf("\n");
clean(chuan,'\0'); //清空;
clean(can,'\0');
}
}