温姑娘


私信TA

用户名:151210107

访问量:6794

签 名:

等  级
排  名 6460
经  验 1358
参赛次数 1
文章发表 6
年  龄 0
在职情况 学生
学  校 平顶山学院
专  业

  自我简介:

TA的其他文章

解题思路:

暴力即可



注意事项:





参考代码:

#include <iostream>
#include <stdio.h> 
#include <algorithm> 
#include <string.h> 
#include <vector>

using namespace std;

int a[10];
int main() {
	int n,sum,tmp,cnt,num;
	while(~scanf("%d",&n)) {
		num = 0;
		for(int i = 10000; i <= 999999; i++) {
			sum = 0;
			tmp = i;
			cnt = 0;
			while(tmp) {
			    sum += tmp%10;
			    a[cnt++] = tmp%10;
				tmp = tmp/10; 
			}
			bool flag = true;
			//五位数 
			if(cnt%2){
				if(a[0]!=a[4] || a[1]!=a[3]) flag = false;
			}
			else {
				if(a[0]!=a[5] || a[1]!=a[4] || a[2]!=a[3]) flag = false;
			}
			if(sum != n) flag = false;
			if(flag) {
				num++;
				printf("%d\n",i);
			}
		}	
		if(num==0) {
			printf("-1\n");
		}
	}
	return 0;
}


 

0.0分

0 人评分

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

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区