试着写了一下,写的不好请见谅:
#include<iostream>
#include<vector>
using std::vector;
using std::cin;
using std::cout;
using std::endl;
int main()
{
//num分别存放1000至9999的整数,part1是数字的前半部,part2是后半部
int num=0,part1=0,part2=0;
vector<int> ivec;
for(num=1000; num<=9999 ; ++num)
{
part1=num/100;
part2=num%100;
if((part1 + part2)*(part1 + part2)==num)
ivec.push_back(num);
}
cout<<"Please enter an num( 0<num<="<<ivec.size()<<" ):";
cin>>num;
cout<<ivec[num-1]<<endl;
return 0;
}
#include<iostream>
#include<vector>
using std::vector;
using std::cin;
using std::cout;
using std::endl;
int main()
{
//num分别存放1000至9999的整数,part1是数字的前半部,part2是后半部
int num=0,part1=0,part2=0;
vector<int> ivec;
for(num=1000; num<=9999 ; ++num)
{
part1=num/100;
part2=num%100;
if((part1 + part2)*(part1 + part2)==num)
ivec.push_back(num);
}
cout<<"Please enter an num( 0<num<="<<ivec.size()<<" ):";
cin>>num;
cout<<ivec[num-1]<<endl;
return 0;
}