2015-The 6th Blue Bridge Cup Individual Provincial Competition (Software) Zhenti C University Group A 3. Wonderful Numbers

Title description

Xiao Ming found a strange number. Its square and cube use each of the 10 numbers from 0 to 9 and only use it once.
Can you guess what this number is?
Please fill in the number, do not fill in any redundant content.

analysis

First determine that the approximate range of this number is 41 to 100 (the square digit is 4, and the cube digit is 6), and then perform a brute force search (the code is not confident enough)

Code

#include<iostream>
using namespace std;
int main(){
    
    
	int p,l,a[11],ans;
	for(int i=41;i<100;i++){
    
    
		int b[11]={
    
    0,0,0,0,0,0,0,0,0,0},num=0;//每次循环一定要重新初始化计数数组以及 num !
		p=i*i;
		l=i*i*i;
		for(int j=0;j<4;j++){
    
    
			a[j]=p%10;
			p/=10;
		}
		for(int k=4;k<10;k++){
    
    
			a[k]=l%10;
			l/=10;
		}
		for(int e=0;e<10;e++){
    
    
			switch(a[e]){
    
    
				case 0:b[0]++;break;
				case 1:b[1]++;break;
				case 2:b[2]++;break;
				case 3:b[3]++;break;
				case 4:b[4]++;break;
				case 5:b[5]++;break;
				case 6:b[6]++;break;
				case 7:b[7]++;break;
				case 8:b[8]++;break;
				case 9:b[9]++;break;
			}
		}
		for(int m=0;m<10;m++){
    
    
			if(b[m]==1)
				num++;
		}
		if(num==10){
    
    
			ans=i;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Output 69

Guess you like

Origin blog.csdn.net/interestingddd/article/details/114889772