Educational Codeforces Round 160 (Rated for Div. 2)
A. Rating Increase
字符串处理
#include<bits/stdc++.h>
using namespace std;
void solve(){
string s;
cin>>s;
int n=s.size();
s=" "+s;
for(int i=1;i<=n-1;i++){
string t="";
for(int j=1;j<=i;j++){
t=t+s[j];
}
string x="";
for(int j=i+1;j<=n;j++)x=x+s[j];
int a=0;
int b=0;
int k=1;
for(int j=t.size()-1;j>=0;j--){
a+=k*t[j];
k*=10;
}
k=1;
for(int j=x.size()-1;j>=0;j--){
b+=k*x[j];
k*=10;
}
if(x[0]!='0'&&a<b){
cout<<t<<" "<<x<<"\n";
return;
}
}
cout<<-1<<"\n";
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
cin>>t;
for(int i=1;i<=t;i++)solve();
return 0;
}
B. Swap and Delete
按贪心来说肯定能交换就交换划算,所以记录0,1个数,遇见0就拿已有的1交换,同理1,当手里的硬币不足以交换时只能删除
#include<bits/stdc++.h>
using namespace std;
void solve(){
string s;
cin>>s;
int m=s.size();
int a=0,b=0;
for(int i=0;i<m;i++){
if(s[i]=='0')a++;
else b++;
}
int ans=0;
for(int i=0;i<m;i++){
if(s[i]=='0'){
if(b)b--;
else{
cout<<m-i<<"\n";
return;
}
}
if(s[i]=='1'){
if(a)a--;
else{
cout<<m-i<<"\n";
return;
}
}
}
cout<<0<<"\n";
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
cin>>t;
for(int i=1;i<=t;i++)solve();
return 0;
}