亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1750 | 回復(fù): 0
打印 上一主題 下一主題

京東眾籌抽獎算法(轉(zhuǎn)載娛樂) [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2015-07-10 13:22 |只看該作者 |倒序瀏覽
無聊看到京東眾籌的抽獎算法,就簡單的實現(xiàn)了下,依據(jù)第三版抽獎規(guī)則編寫的:http://zbbs.jd.com/thread-399-1-1.html
JDRoll.png


JDRoll.java
  1. import java.util.Scanner;

  2. public class JDRoll {

  3.     public static void main(String[] args) {
  4.         System.out.println("單行輸入,用空格隔開!");
  5.         System.out.println("雙色球最大、最小、藍(lán)色、參與人數(shù)、獲獎名額:");
  6.         Scanner scan = new Scanner(System.in);
  7.         //雙色球最大最小及藍(lán)色球A
  8.         String aStr = scan.next() + scan.next() + scan.next();
  9.         int a = Integer.valueOf(aStr);
  10.         System.out.println("A: " + a);
  11.         //人數(shù)N
  12.         String nStr = scan.next();
  13.         int n = Integer.valueOf(nStr);
  14.         System.out.println("N: " + n);
  15.         //名額P
  16.         String pStr = scan.next();
  17.         int p = Integer.valueOf(pStr);
  18.         System.out.println("P: " + p);
  19.         //人數(shù)N除以名額P,取商B
  20.         int b = n/p;
  21.         System.out.println("N / P = B: " + b);

  22.         //A除以B,余數(shù)為首個中獎號X
  23.         int x = a%b;
  24.         System.out.println("A % B = X: " + x);

  25.         int[] rs = new int[p];
  26.         rs[0] = x;

  27.         //其他中獎號X+B,X+2B,X+3B,......,X+(P-1)B
  28.         int i = 1;
  29.         while(i < p) {
  30.             rs[i] = x + i*b;
  31.             ++i;
  32.         }

  33.         for (int j = 0; j < p; ++j) {
  34.             System.out.println("第" + (j+1) + "個中獎號碼為:" + rs[j]);
  35.         }
  36.     }

  37. }
復(fù)制代碼
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP