自除数 同学的对比我的(俺真菜)

#include<iostream>
#include<string>
#include<vector>
using namespace std;

bool test(int input)
{
 int zznum = input;
 vector<int> nums;

 bool isZero = false;
 int numNumber = 0;
 int temp = 1; //位数
 while (input != 0)
 {
  int t = input % 10;
  input = input / 10;
  nums.push_back(t);
  numNumber++;
  if (t == 0)
   isZero = true;
 }

 if (!isZero)
 {
  bool isZhengchu = true;
  for (auto it : nums)
  {
   if (zznum % it != 0)
   {
    isZhengchu = false;
   }
  }
  if (isZhengchu)
   return true;
 }

 return false;
}

int main()
{
 int left = 1;
 int right = 22;
 for (int i = left; i <= right; i++)
 {
  if (test(i))
   cout << i << endl;
 }


 system("pause");
 return 0;

}//出口

同学写的对比我写的  哎难搞

package com.operator;

public class Selfdemo1 {
    public static void main(String[] args) {
        int[] t = new int[5];
        int left = 10;
        int right = 85;

        for (; left <= right; left++) {
            int num=left;
            int[] a = new int[5];
            a[0]=0;a[1]=0;a[2]=0;a[3]=0;a[4]=0;
            getnum(num, 0, 10, a);

boolean flag=false; boolean flagb=false;
            for (int x = 0; x < a.length; x++) {

                if ((x>0)&&(a[x]==0))  //一个0的前一位是可除非0数
                {if(a[x-1]!=0)
                {int axa;
                axa=num%a[x-1];
                    if(axa==0)
                       flagb=true;

                }
                if ((x>0)&&(a[x]==0)&&flagb&&a[x-1]==0)    //在前面基础上的下一个数还是0
                {
                    flagb=true;
                }}
                if (a[a.length-1]!=0)flagb=true;
                if(a[x]!=0) {
                    if (num % a[x] == 0) {
                        flag= true;
                    }
                }else flag=true;
                if(a[0]==0){flag=false;}
              if(!(flag))break;

               }


            if (flag&&flagb){ System.out.println(num);}
        }
    }

    public static int[] getnum(int a,int x,int z,int[]t) {


        if (a/z >=1) {

            t[x] = a-a/z*10;
            x++;

            getnum(a/z,x,z,t);
        } else if (a/z <1)t[x]=a;
            return t;

    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值