#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main() {
vector<int> in_data(4,0);
int i = 0;
while (i<4) {
cin >> in_data[i];
i++;
}
sort(in_data.begin(),in_data.end());
if ((in_data[0] + in_data[3]) == (in_data[1] + in_data[2]))
cout << "YES";
else if((in_data[0] + in_data[1] + in_data[3]) == (in_data[2]))
cout << "YES";
else
cout << "NO";
return 0;
}
第一道AC,题意好理解,解也好写
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
// void call(string &num, long long pos, long long len, long long chance){
// if((pos>len-1) || !chance)
// return;
// if(len == 1){
// num[0] = '0';
// return;
// }
// if(!pos){
// if(num[pos] == '1')
// call(num,pos+1,len,chance);
// else{
// num[pos] = '1';
// call(num,pos+1,len,chance-1);
// }
// }else{
// if(!num[pos])
// call(num,pos+1,len,chance);
// else{
// num[pos] = '0';
// call(num,pos+1,len,chance-1);
// }
// }
// }
// int main() {
// string num;
// long long N,K;
// cin>>N>>K;
// cin>>num;
// call(num,0,N,K);
// cout<<num;
// return 0;
// }
int main()
{
// int n,m,k;
// string str;
// while(cin>>n>>k)
// {
// cin>>str;
// if(!k)
// cout<<str<<endl;
// else if(n==1)
// cout<<0<<endl;
// else
// {
// if(str[0]!='1')
// {str[0] = '1';k--;}
// for(int i=1; i<str.size() && k; i++)
// {
// if(str[i]!='0')
// {str[i]='0';k--;}
// }
// cout<<str<<endl;
// }
// }
int n,m,k;
string str;
cin>>n>>k;
cin>>str;
if(!k)
cout<<str<<endl;
else if(n==1)
cout<<0<<endl;
else{
if(str[0]!='1')
{str[0] = '1';k--;}
if(k>str.size())
string mid_str(str.size(),'0');
else
string mid_str(k,'0');
string tail_str(str.substr(k+1));
cout<<("1"+mid_str+tail_str)<<endl;
}
terurn 0;
}
第二道有点说法,按照要求模拟迭代过程AC;
但是想要简化一下:
1.先写了递归,好理解,但是数据长度太大,估计爆栈,所以不要用递归
2.用迭代的话,时间复杂度有点高。然后就找列一下规律,实际上就是原数据的后m-k位是不需要修改的,那就直接拼接两个字符串就完事了。但是很奇葩,死活过不了第五个用例,很想知道BUG在哪