swust_2020卓越班选拔

本文精选了多种算法题目的解决方案,包括时间计算、去重、二进制转换、数学规律识别、邮件阅读策略、细菌繁殖模拟、洞穴封堵策略、蠕虫逃脱分析以及重复字符查找等,展示了丰富的算法应用实例。

前言:代码仅供参考,不是最优代码,存在问题的话,请指正,还有就是题目顺序搞忘了,名字只大体记得。。。


时间A+B

大意:给你两个时间相加,简单模拟时间的运算

#include<bits/stdc++.h>
using namespace std;
typedef struct time{
	int h;
	int m;
	int s;
}ti;
int main(){
	ti t1, t2;
	while(cin>>t1.h>>t1.m>>t1.s>>t2.h>>t2.m>>t2.s){
		ti t3;
		t3.h=0;t3.m=0;t3.s=0;
		t3.s=t1.s+t2.s;
		if(t3.s>=60){
			t3.m+=1;t3.s-=60;
		}
		t3.m=t3.m+t1.m+t2.m;
		if(t3.m>=60){
			t3.h+=1;t3.m-=60;
		}
		t3.h=t1.h+t2.h+t3.h;
		if(t3.h<10){
			cout<<"0";
		}
		cout<<t3.h<<":";
		if(t3.m<10){
			cout<<"0";
		}
		cout<<t3.m<<":";
		if(t3.s<10){
			cout<<"0";
		}
		cout<<t3.s<<"\n";			
	}	
}

去重数

大意 去除相同的数。。
因为是在100内,所以直接开个数组标记一下就行了,不用多想

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int a[200
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值