UDP广播协议叫吃饭


私信TA

用户名:Mustenaka

访问量:136591

签 名:

个人博客www.mustenaka.cn

等  级
排  名 12
经  验 23922
参赛次数 8
文章发表 197
年  龄 3
在职情况 学生
学  校 Sky_box
专  业 NE

  自我简介:

欢迎光临我的博客www.mustenaka.cn,Python,C#,U3D,C/C++开发合作可以找我

TA的其他文章

解题思路:
    被别人家的小白赛搞自闭了,来写一下水题,找回信心


    思路:利用数组+整形数据进行模拟操作,善用C++的sort进行排序,解决问题
参考代码:

#include<bits/stdc++.h>
#define hh ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
string fin="6174",input;
int number[5];
int hig_number[5],low_number[5];
int hig_n,low_n,cnt_n;
const int fin_n=6174;
int ans=0;

bool cmp(int a,int b){
	return a>b;
}
int main(){
	hh;
	cin>>input;
	if(input==fin){
		cout<<ans<<endl;
		exit(0);
	}
	
	for(int i=0;i<input.length();i++){
		hig_number[i]=input[i]-'0';
		low_number[i]=input[i]-'0';
	}
	sort(hig_number,hig_number+4,cmp);
	sort(low_number,low_number+4);
	while(cnt_n!=fin_n){
		hig_n=0,low_n=0;
		for(int i=0,j=1000;i<4;i++,j/=10){
			hig_n+=hig_number[i]*j;
			low_n+=low_number[i]*j;
		}
		cnt_n=hig_n-low_n;
		int temp=cnt_n;
		for(int i=0;i<4;i++){
			hig_number[i]=temp%10;
			low_number[i]=temp%10;
			temp/=10;
		}
		sort(hig_number,hig_number+4,cmp);
		sort(low_number,low_number+4);
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区