试题 基础练习8 回文数

资源限制

时间限制:1.0s 内存限制:512.0MB

问题描述

1221是一个非常特殊的数,它从左边读和从右边读是一样的,编程求所有这样的四位十进制数。

输出格式

按从小到大的顺序输出满足条件的四位十进制数。

#include<iostream>
#include<set>
#include<sstream>
#include<string>
#include<cmath>
#include<vector>

using namespace std;

int main()
{
    
    

	int target;
	int one, two, tem;
	set<int> search;
	vector<int> result;
	// four-digit number
	for(one = 1;one<10;one++)
		for (two = 0; two < 10; two++)
		{
    
    
			tem = one * 1001 + two * 110;
			if (!search.count(tem))
				result.push_back(tem);
		}

	for (int i = 0;i<result.size();i++)
		for (int j = i; j < result.size(); j++)
		{
    
    
			if (result[i] > result[j])
			{
    
    
				tem = result[i];
				result[i] = result[j];
				result[j] = tem;
			}
		}
	for (int i = 0; i < result.size(); i++)
	{
    
    
		cout << result[i] << endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_39117858/article/details/104222322