AtCoder Beginner Contest 196

A.Difference Max

题意:给你x和y的区间求x-y的最大值

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	b-=c;
	cout<<b<<endl;
}

B - Round Down

题意:输入一个x,1<=x<=10^100,看到这就知道用字符串处理,删掉小数点后的数即可。

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s2,s1;
	cin>>s1;
	for(int i=0;s1[i]!='.'&&s1[i]!='\0';i++){
		s2+=s1[i];
	}
	cout<<s2<<endl;
}

C - Doubled

题意:求有多少个整数,x在1和N(包括)之间,满足以下条件:
①X的十进制表示法(不带前导零)有偶数位数
②第一和第二半部是相同的字符串。
思路:模拟一下推一下就会发现规律,当初做的很混乱= =好歹也还是过了。贴一下恶心一下自己

#include<bits/stdc++.h>
#define int long long 
using namespace std;
int sw(int n){
	int cnt=0;
	while(n!=0){
		n/=10;
		cnt++;
	}
	return cnt;
}
int jg(int n){
	int i,j,cnt=0,m1=0,m2=0;
	cnt=sw(n);
	for(i=0;i<cnt;i++){
		if(i<cnt/2){
			m1+=(n%10)*pow(10,i);
			n/=10;
		}
		else {
			m2+=(n%10)*pow(10,i-cnt/2);
			n/=10;
		}
	}
	if(m1<m2) cnt=m2-1;
	else cnt=m2;
	return cnt;
}
signed main()
{
	int n,i,j;
	cin>>n;
	int q=jg(n);
	if(n<=10){
		cout<<0<<endl;
	}
	else if(q==-1){
		if(sw(n)%2==0){
			for(i=0;i<(sw(n)-2)/2;i++){
				cout<<9;
			}
			cout<<endl;
		}
		else {
			for(i=0;i<(sw(n)+1)/2;i++)
				cout<<9;
			cout<<endl;
		}
	}
	else {
		if(sw(n)%2==0){
			cout<<q<<endl;
		}
		else {
			for(i=0;i<(sw(n)-1)/2;i++){
				cout<<9;
			}
			cout<<endl;
		}
	}
}

然而正解是用个字符串的函数

#include <iostream>
#include <string>
using namespace std;
using ll = long long;

int main(){
    ll N;
    cin >> N;
    for(ll i = 1; ; i++) if(stoll(to_string(i) + to_string(i)) > N){
        cout << i - 1 << endl;
        return 0;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值