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;
}
}