侧边栏壁纸
博主头像
王小木人

这是很长,很好的一生

  • 累计撰写 141 篇文章
  • 累计创建 43 个标签
  • 累计收到 9 条评论

目 录CONTENT

文章目录

年龄谜题 C++

王小木人
2021-05-22 / 0 评论 / 0 点赞 / 893 阅读 / 887 字

年龄谜题 美国数学家维纳(N.Wiener)智力早熟,11 岁就上了大学。他曾在 1935~1936 年应
邀来中国清华大学讲学。一次,他参加某个重要会议,年轻的脸孔引人注目。于是 有人询问他的年龄,他回答说:“我年龄的立方是个 4 位数。我年龄的 4 次方是个 6 位数。这 10 个数字正好包含了从 0 到 9 这 10 个数字,每个都恰好出现 1 次。” 请你推算一下,他当时到底有多年轻。

#include <iostream>
#include<string.h> 
#include<sstream>
#include<cmath>
#include<string>
#include <stdlib.h>
#include <stdio.h>
using namespace std; 


int main()
{
 
  for(int i=0;i<100;i++)
  
  {
   int four=pow(i,3),six=pow(i,4);
   if(four<1000||four>9999)
   continue;
   if(six<100000||six>999999)
   continue;
   string stri;
    stringstream stra,strb;
    stra<<four;strb<<six;
    stri=stra.str()+strb.str();
   for(int j=0;j<10;j++)
   {
      bool ishava=false;
      for(int k=0;k<10;k++)
      {
       
         int c=stri[k]-48;
       if(c==j)
       {
       ishava=true;
       continue;
       }
     
      }
      if(ishava==false)
      break;
      if(j==9)
      cout<<i<<"="<<stri<<'\n';
   } 
   
   
  }
  
 
    return 0;
} 
0

评论区