在这次做题过程中,自己先写了个代码,提交后发现有几个没通过,在牛客网又测试了一次后,发现类似于“3”的这种用例没有考虑到,在自己想过之后,又参考了别人的代码后,重新写了一次,学到不少。
代码如下:
#include#include #include using namespace std; bool cmp(int a,int b) { return a>b; } int main(){ string str; int arr[4]={0}; char a; cin >>str; while(str.size()<4) { str=str+"0"; } //直接对字符串进行排序 string max=str,min=str; sort(min.begin(),min.end()) ; sort(max.begin(),max.end(),cmp); if(max==min) { cout << max <<" - "<< min <<" = " << "0000" <<'n'; } else{ while(1){ cout < 在参考别人代码后,发现有很多自己以前不知道的方法。
像 stoi函数
注意
string 类型的方法今天是有收获的



