洛谷 CF1107A 题解
题目传送门
思路:
这道题可以分情况考虑:
- \(N = 2\),并且 \(s0 ≤ s1\),可以分解。如果 \(s0 > s1\),不可以分解。
- \(N > 2\),肯定可以分解,把 \(s\) 分成两部分,\(s0\) 为一部分,剩下的为一部分。
- \(N < 2\),肯定不可以分解。
代码:
#include <bits/stdc++.h>
using namespace std;
int q,n;
string str;
int main(){
cin>>q;
while(q--){
cin>>n>>str;
if(n<2){ //n的值小于2肯定不可以
cout<<"NO"<<endl;
}
else if(n>2){ //n的值大于2肯定可以成功
cout<<"YES"<<endl;
cout<<"2"<<endl;
cout<<str[0]<<" ";
for(int i=1;i<n;i++) cout<<str[i];
cout<<endl;
}
else if(n==2){
if(str[0]-'0'>=str[1]-'0'){
cout<<"NO"<<endl;
}
else{
cout<<"YES"<<endl;
cout<<"2"<<endl;
cout<<str[0]<<" "<<str[1]<<endl;
}
}
}
return 0;
}
本文来自博客园,作者:PandaBlack,转载请注明原文链接:https://www.cnblogs.com/liu-black/p/cf1107a-tijie.html