返回值为指针类型

#include<cstdio>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
int* get(int a)   //获取每一位数字
{
    int *num;
    num = (int*)malloc(sizeof(int)*5);
    int sp = 0;
    while(a)       //9087
    {
        int s = a%10;  //获取个位
        num[sp++] = s;
        a = a/10;
    }
    return num;
}
int main()
{
    for(int i = 1000;i<10000;i++)
    {
        int j = i*9;
        if(j>=10000)continue;
        int *s1 = get(i);
        int *s2 = get(j);
        bool re = true;
        for(int p = 0;p<4;p++)
        {
            if(s1[p]==s2[3-p])continue;
            else
                {
                    re = false;
                    break;
                }
        }
        if(re)cout<<i<<endl;
    }
    return 0;
} 

猜你喜欢

转载自blog.csdn.net/luoshiyong123/article/details/104785609
今日推荐