t1/t2训练

A

题意

一个字符串,第i个字符被重复i个,得到一个新的字符串。现在给出该新字符串,求原来的字符串。

Sample Input
6
baabbb
Sample Output
bab

Sample Input 2
10
ooopppssss
Sample Output 2
oops

思路

按题意,erase删除就好。

代码

#include<iostream>
#include<string>
using namespace std;

int main(void){
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
        s.erase(i,i);
    cout<<s<<endl;
    return 0;
}

B

题意

从原点去各个点营救人(需带回原点),速度为50km/s,每人上船要1s,下船要0.5s。

Sample Input
1
30 40 3
Sample Output
7

思路

算距离,得到总时间,上取整即可

总结

WA了2遍,竟然是因为a,b,c用了int。
a,b,c应声明为double,平方计算中为精确希望得到的是浮点数而不是整数。

代码

#include<cstdio>
#include<cmath>
using namespace std;

int main(void){
    int n;
    scanf("%d",&n);
    double time=0;
    for(int i=0;i<n;i++){
        double a,b,c;
        scanf("%lf%lf%lf",&a,&b,&c);
        time+=2*(sqrt(pow(a,2)+pow(b,2))/50.) + c*1.5;
    }
    int res=ceil(time);
    printf("%d\n",res);
    return 0;
}

C

题意

一个整数的每一位相加得到一个新的整数,不断重复直到只剩下1位,即为结果。

Sample Input
24
Sample Output
6

思路

按string类型输入,按题意循环计算即可

代码

#include<iostream>
#include<string>
#include<sstream>
using namespace std;

int main(void){
	string s;
	cin>>s;
	while(s.size()!=1){
		int num=0;
		int z='0';
		for(auto i:s) num+=i-z;
		stringstream is;
		is<<num;
		is>>s;
	}
	cout<<s<<endl;
	return 0;
}

D

题意

第1人:关所有的灯
第2人:调整所有2的倍数的灯为相反状态
第i人,调整所有i的倍数的灯为相反状态

Sample Input
10 10
Sample Output
1,4,9

思路

按题意,写循环处理即可

总结

wa了1次,没搞清楚题意

代码

#include<cstdio>
using namespace std;

bool light[5005];
int main(void){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=2;i<=m;i++){
		for(int x=1;;x++){
			int j=i*x;
			if(j>n) break;
			light[j]=1-light[j];
		}
	}
	for(int i=1;i<=n;i++){
		if(light[i]==0){
			if(i!=1) printf(",");
			printf("%d",i);
		}
	}

	return 0;
}

E

题意

剪刀石头布,给出n个场次的出拳结果,求双方分别获胜的次数,并输出相应内容。

Sample Input
3
J S
S S
B J
Sample Output
huaye

思路

按输入,判输赢,记结果…

总结

居然wa了2次,不知道为什么,后来发现用的scanf没有顺利输入…
由于是在场上,就更换cin作输入
应该要总结一下scanf的用法了,好几次都因为scanf wa…

代码

#include<iostream>
using namespace std;

bool check(char s,char h){
	if(s=='S'&&h=='J')
		return true;
	if(s=='J'&&h=='B')
		return true;
	if(s=='B'&&h=='S')
		return true;
	return false;
}

int main(void){
	int n;
	int sRes=0,hRes=0;
	cin>>n;
	for(int i=0;i<n;i++){
		char s,h;
		cin>>s>>h;
		if(check(s,h)) sRes++;
		if(check(h,s)) hRes++;
	}
	if(sRes>hRes)
		cout<<"suantou"<<endl;
	else if(sRes<hRes)
		cout<<"huaye"<<endl;
	else
		cout<<"QAQ"<<endl;
	return 0;
}

F

题意

还是猜拳,0是石头,2是剪刀,5是布。
A、B有规律出拳,求进行n局,谁赢的次数较多

Sample Input
10 3 4
0 2 5
0 5 0 2
Sample Output
A

思路

模运算,取出拳,判输赢…

代码

#include<iostream>
using namespace std;

int NA[105],NB[105];
bool check(int s,int h){
	if(s==0&&h==2)
		return true;
	if(s==2&&h==5)
		return true;
	if(s==5&&h==0)
		return true;
	return false;
}

int main(void){
	int n,na,nb;
	int ares=0,bres=0;
	cin>>n>>na>>nb;
	for(int i=0;i<na;i++)
		cin>>NA[i];
	for(int i=0;i<nb;i++)
		cin>>NB[i];
	for(int i=0;i<n;i++){
		int a=i%na;
		int b=i%nb;
		if(check(NA[a],NB[b])) ares++;
		else if(check(NB[b],NA[a])) bres++;
	}
	if(ares>bres)
		cout<<"A"<<endl;
	else if(ares<bres)
		cout<<"B"<<endl;
	else
		cout<<"draw"<<endl;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值