2013年蓝桥杯省赛A组填空题 1.排它平方数 知识点:暴力枚举

1.排它平方数 - 蓝桥云课 (lanqiao.cn)

这是我写的,跑不出来结果: 思想是把x和x*x全部拆分,放到vector1,vector2里,然后遍历vector1,vector2,如果vector1和vectorr2的每一位都不同就输出

js 复制代码
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
vector<LL>t1,t2;
int flag=0;
int main()
{
	for(int i=100000;i<1000000;i++)
	{
		LL sum=i*i;
			
	     while(sum)
		{
			t1.push_back(sum%10);
			sum/=10;
		}
				
		while(i)
		{
			t2.push_back(i%10);
			i/=10;
		}
		

			for(int j=0;j<t2.size();j++)
			{	   
			 for(int i=0;i<t1.size();i++)
		   {
				if(t1[i]!=t2[j]&&(t2[0]!=t2[1]&&t2[1]!=t2[3]&&t2[3]!=t2[4]&&t2[4]!=t2[5]&&t2[5]))flag=1;
			}
		 } 
		if(flag)cout<<i;
	}
	
	
	
	return 0;
}

这是别人写的: 2013年c++A组题2_哔哩哔哩_bilibili

js 复制代码
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

//void is2(LL x,string &str)
//{
//	stringstream ss;
//	ss<<x;
//	ss>>str; 
//}
bool check(LL a,LL b)
{
	string str_a=to_string(a);
	string str_b=to_string(b); 


 for(int i=0;i<str_a.size();i++)
 {
 	if(str_b.find(str_a[i])!=string::npos)
 	return false;
 }
return true;
}
int main()
{
	for(int i=1;i<10;i++)
	{
		for(int j=0;j<10;j++)
		{
			if(i!=j)
			for(int k=0;k<10;k++)
			{   if(k!=i&&k!=j)
				for(int l=0;l<10;l++)
				{
					if(l!=i&&l!=j&&l!=k)
					for(int m=0;m<10;m++)
					{
						if(m!=i&&m!=j&&m!=k&&m!=l)
						for(int n=0;n<10;n++)
						{
							if(n!=i&&n!=j&&n!=k&&n!=l&&n!=m)
							{
								LL x=i*100000+j*10000+k*1000+l*100+m*10+n;
								
								if(check(x,x*x)) 
								cout<<x<<" "<<x*x<<endl; 
							}
						}
					}
				}
			}
		 } 
	}
	
	return 0;
}
相关推荐
mmz12077 分钟前
前缀和问题(c++)
c++·算法·图论
努力学算法的蒟蒻33 分钟前
day27(12.7)——leetcode面试经典150
算法·leetcode·面试
甄心爱学习1 小时前
CSP认证 备考(python)
数据结构·python·算法·动态规划
kyle~2 小时前
排序---常用排序算法汇总
数据结构·算法·排序算法
AndrewHZ2 小时前
【遥感图像入门】DEM数据处理核心算法与Python实操指南
图像处理·python·算法·dem·高程数据·遥感图像·差值算法
CoderYanger2 小时前
动态规划算法-子序列问题(数组中不连续的一段):28.摆动序列
java·算法·leetcode·动态规划·1024程序员节
有时间要学习3 小时前
面试150——第二周
数据结构·算法·leetcode
liu****3 小时前
3.链表讲解
c语言·开发语言·数据结构·算法·链表
第二只羽毛3 小时前
C++ 高性能编程要点
大数据·开发语言·c++·算法