zoukankan      html  css  js  c++  java
  • 蓝桥杯 历届试题 回文数字 (水)

      历届试题 回文数字  
    时间限制:1.0s   内存限制:256.0MB
        
    问题描述
      观察数字:12321,123321 都有一个共同的特征,无论从左到右读还是从右向左读,都是相同的。这样的数字叫做:回文数字。

      本题要求你找到一些5位或6位的十进制数字。满足如下要求:
      该数字的各个数位之和等于输入的整数。
    输入格式
      一个正整数 n (10<n<100), 表示要求满足的数位和。
    输出格式
      若干行,每行包含一个满足要求的5位或6位整数。
      数字按从小到大的顺序排列。
      如果没有满足条件的,输出:-1
    样例输入
    44
    样例输出
    99899
    499994
    589985
    598895
    679976
    688886
    697796
    769967
    778877
    787787
    796697
    859958
    868868
    877778
    886688
    895598
    949949
    958859
    967769
    976679
    985589
    994499
    样例输入
    60
    样例输出
    -1

    暴力就行了;

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    #include<algorithm>
    //#include<windows.h>
    using namespace std;
    #define mem(x,y) memset(x,y,sizeof(x))
    #define SI(x) scanf("%d",&x)
    #define PI(x) printf("%d",x)
    #define P_ printf(" ")
    const int INF=0x3f3f3f3f;
    typedef long long LL;
    
    int main(){
    	int N;
    	SI(N);
    	bool flot=false;
    	for(int i=10000;i<1000000;i++){
    		int cur=0;
    		int temp=i;
    		int a,b,c,d,e,f,t=0;
    		//bool yy=true;
    		while(temp){
    			cur+=temp%10;
    			t++;
    			if(t==1)a=temp%10;
    			if(t==2)b=temp%10;
    			if(t==3)c=temp%10;
    			if(t==4)d=temp%10;
    			if(t==5)e=temp%10;
    			if(t==6)f=temp%10;
    			temp/=10;
    		}
    		if(t==5){
    			if(a!=e||b!=d)continue;
    		}
    		if(t==6){
    			if(a!=f||b!=e||c!=d)continue;
    		}
    		//if(i==189998)printf("%d %d %d
    ",a,b,c);
    		//if(!yy)continue;
    		if(cur==N){
    			printf("%d
    ",i);
    		//	system("pause");
    			flot=true;
    		}
    	}
    	if(!flot)puts("-1");
    	return 0;
    }
    

      

  • 相关阅读:
    8.池化内存分配
    7.netty内存管理-ByteBuf
    6.ChannelPipeline
    5.接入客户端连接
    4.Netty执行IO事件和非IO任务
    3.NioEventLoop的启动和执行
    2.NioEventLoop的创建
    1.netty服务端的创建
    微信订阅号开发初探
    jmeter自动化脚本编写
  • 原文地址:https://www.cnblogs.com/handsomecui/p/5117394.html
Copyright © 2011-2022 走看看