int total_money_cent = 1000; // 红包总金额 单位:分
int total_people = 8; // 抢红包总人数
       int[] array = new int[total_money_cent];
for (int i = ; i < total_money_cent; i++)
{
array[i] = i;
} Random random = new Random();
for (int i = ; i < total_people; i++)
{
int index = random.Next(total_money_cent - i) + i;
int temp = array[i];
array[i] = array[index];
array[index] = temp;
}
array[total_people] = total_money_cent; Array.Sort(array, , total_people + );
for (int i = ; i <= total_people; i++)
{
Console.Write("第 {0} 个红包:{1}.{2} 元,剩下 {3}.{4} 元\n", i,
(array[i] - array[i - ]) / , (array[i] - array[i - ]) % ,
(total_money_cent - array[i]) / , (total_money_cent - array[i]) % );
}

Java

int total_money_cent; // 红包总金额
int total_people; // 抢红包总人数 total_money_cent = 1000;
total_people = 8; int array[] = new int[total_money_cent];
for (int i = 0; i < total_money_cent; i++) {
array[i] = i;
} Random random = new Random();
for (int i = 1; i < total_people; i++) {
int index = random.nextInt(total_money_cent - i) + i;
int temp = array[i];
array[i] = array[index];
array[index] = temp;
}
array[total_people] = total_money_cent;
Arrays.sort(array, 0, total_people + 1);
for (int i = 1; i <= total_people; i++) {
System.out.printf("第 %d 个红包:%d.%02d 元,剩下 %d.%02d 元\n", i,
(array[i] - array[i-1]) / 100, (array[i] - array[i-1]) % 100 ,
(total_money_cent - array[i]) / 100, (total_money_cent - array[i]) % 100);
}

最新文章

  1. PHP中遍历XML之SimpleXML
  2. Tensorflow使用环境配置
  3. Python学习教程
  4. Giving Data Backup Option in Oracle Forms 6i
  5. [leetcode] Contains Duplicate
  6. 分享一个Cnblogs简易APP
  7. mysql从只有一个备份文件(多个数据库的备份)中恢复数据到指定数据库
  8. python小算法(一)
  9. HDu -2844 Coins多重背包
  10. Linux批量重命名
  11. OAuthBase.cs
  12. [转]使用openssl库实现RSA、AES数据加密
  13. linux 下 zookeeper安装
  14. web SPA项目目录、命名规范
  15. Android为TV端助力 Intent匹配action,category和data原则
  16. CSS 的三种样式 内联 内部 外部
  17. iTOP-6818开发板支持AXP228电源管理[官方推荐最佳匹配]_支持动态调频
  18. 【PMP】项目采购管理~重点知识
  19. php 的函数
  20. Win10系列:VC++媒体播放控制4

热门文章

  1. manacher马拉车算法
  2. java实现扫二维码登录功能
  3. json数据的格式,JavaScript、jQuery读取json数据
  4. KNN-K近邻算法(1)
  5. 用PowerPoint中的VB实现课件中的智能交互
  6. eclipse安装Aptana 插件,并设置使之能提示css,js,html,帮助编写代码
  7. 好用的window命令
  8. 【ZJOI2017 Round1练习&amp;&amp;BZOJ5353】D7T2 guess(费用流)
  9. Linux下汇编语言学习笔记27 ---
  10. HDU 5876 补图 单源 最短路