蓝桥杯历届-猜年龄

来源:互联网 发布:h5小游戏网站源码 编辑:程序博客网 时间:2024/05/10 10:23

蓝桥杯历届-猜年龄


题目标题: 猜年龄

美国数学家维纳(N.Wiener)智力早熟,11岁就上了大学。他曾在1935~1936年应邀来中国清华大学讲学。一次,他参加某个重要会议,年轻的脸孔引人注目。于是有人询问他的年龄,他回答说:“我年龄的立方是个4位数。我年龄的4次方是个6位数。这10个数字正好包含了从0到9这10个数字,每个都恰好出现1次。”请你推算一下,他当时到底有多年轻。通过浏览器,直接提交他那时的年龄数字。注意:不要提交解答过程,或其它的说明文字。
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>using namespace std;char s1[20], s2[20];bool isSame(char *s1) {    char s3[] = "0123456789";    for (int i = 0; i < 10; i++) {        if (s1[i] != s3[i]) return false;    }    return true;}int main() {    for (int y = 1; y < 100; y++) {        int s = y*y*y;        int ss = y*y*y*y;        if (s > 999 && s <= 9999 && ss > 99999 && ss <= 999999) {            sprintf(s1, "%d", s);            sprintf(s2, "%d", ss);            strcat(s1, s2);            sort(s1, s1+strlen(s1));            if (isSame(s1)){                cout << y << endl;                break;            }        }    }    return 0;}

答案为18


0 0