zoukankan      html  css  js  c++  java
  • PAT数学规律题---1019 数字黑洞 (20分)

    1019 数字黑洞 (20分)

    • 一个字符串的写法,坑点就是可能会出现不到4位的数,进行补零
    #include<iostream>
    #include<vector>
    #include<cctype>
    #include<map>
    #include<set>
    #include<sstream>
    #include<string>
    #include<cstdio>
    #include<algorithm>
    
    #define inf 0x3f3f3f3f
    
    const int maxn=10005;
    typedef long long ll;
    
    using namespace std;
    
    int upSort(string s) {
    	sort(s.begin(),s.end(),greater<int>());
    	int num=stoi(s);
    }
    int downSort(string s) {
    	sort(s.begin(),s.end());
    	int num=stoi(s);
    }
    string change(string s){
    	int cnt=s.size();
    	if(cnt<4) {
    		for(int i=0; i<4-cnt; i++) {
    			s='0'+s;
    		}
    	}
    	return s;
    }
    int main() {
    	string s;
    	cin>>s;
    	s=change(s);
    	int a=upSort(s),b=downSort(s);
    	int c=a-b;
    	if(!c) printf("%04d - %04d = 0000
    ",a,a);
    	while(c) {
    		printf("%04d - %04d = %04d
    ",a,b,c);
    		if(c==6174) break;
    		string s1=to_string(c);
    		s1=change(s1);
    		a=upSort(s1),b=downSort(s1);
    		c=a-b;
    	}
    	return 0;
    }
    
    
  • 相关阅读:
    CDQ分治
    [noip模拟赛2017.7.15]
    [noip模拟赛2017.7.11]
    [noip模拟赛2017.7.10]
    [noip模拟赛2017.7.7]
    [noip模拟赛2017.7.6]
    [noip模拟赛2017.7.4]
    回文检测
    mapreduce引用第三方jar
    Spark安装和配置
  • 原文地址:https://www.cnblogs.com/bingers/p/13130358.html
Copyright © 2011-2022 走看看