|
发表于 2015-11-3 17:12:01
|
显示全部楼层
- #include <iostream>
- using namespace std;
- //自己写的pow函数
- int Pow(int val,int how)
- {
- int ret=1;
- for (int i=0;i<how;i++)
- {
- ret*=val;
- }
- return ret;
- }
- //查找字符串中是否有某个字符
- int findchar(char ch,char str[],int n)
- {
- int i=0;
- while(str[i]!=ch&&i<n)
- i++;
- if(i==n)
- i=-1;
- return i;
- }
- int main()
- {
- char a[100]={0};
- char b[100]={0};
- char *e;
- int c=0;
- int d=0;
- for (int i=1;i<999;i++)
- {
- c=Pow(i,2);//二次方
- d=Pow(i,3);//三次方
- itoa(c,a,10);//都转成字符串
- itoa(d,b,10);
- e=strcat(a,b);//并把字符串连接
- if (strlen(e)==10)//如果连接好的字符串正好10位
- {
- int f=0;
- for (int j=0;j<10;j++)//从0-9寻找是否都存在
- {
- if (findchar('0'+j,e,strlen(e))==-1)
- {
- continue;
- }else
- {
- f++;
- }
- if (f==10)//0-9这10个数字都存在
- {
- cout<<i<<"的2次方="<<Pow(i,2)<<","<<i<<"的3次方="<<Pow(i,3)<<"连接起来是"<<e<<"正好全包含0-9这10个数字"<<endl;
- }
- }
- }
- }
- system("pause");
- return 0;
- }
复制代码 |
|