Fastest way to detect duplicate numbers on array vb.net 2005

前端 未结 9 1431
轮回少年
轮回少年 2021-01-20 17:31

I have this project that let user inputs 5 different numbers from 1 to 50. But I want to validate it before saving to DB that i will be 5 unique numbers. What\'s the best an

9条回答
  •  攒了一身酷
    2021-01-20 17:55

    Pseudocode:
    
    integer numbers[50]
    zeroarray(numbers, 50)
    
    integer count = 0;
    while (count < 5)
    {
       integer value = getinput()
    
       if (value >= 1 and value <= 50)
         if (numbers[value] = 0)
         {
            count = count + 1
            numbers[value] = 1
         }
         else
            reject duplicate
       else
         reject invalid
    }
    

提交回复
热议问题