
正文
赛马游戏java代码 java赛马程序
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
田忌赛马C++程序源代码 不用class的
#include iostream
#include string
#include vector
#include algorithm
#include time.h
const std::string GetGongziHorse(std::vectorstd::string horse)
{
int size = horse.size();
int choose = rand()%size;
std::string horseChoosed = horse[choose];
std::vectorstd::string::iterator it
= find(horse.begin(), horse.end(), horseChoosed);
horse.erase(it);
return horseChoosed;
}
const std::string GetTianjiHorse(const std::string horseChoosed)
{
if (strcmp(horseChoosed.c_str(), "千里马") == 0)
return "劣马";
else if (strcmp(horseChoosed.c_str(), "好马") == 0)
return "千里马";
else
return "好马";
}
int main(void)
{
srand(time(NULL));
std::string strHorse[] = {"千里马", "好马", "劣马"};
std::vectorstd::string horseGongzi;
horseGongzi.insert(horseGongzi.end(), strHorse, strHorse + 3);
int i = 1;
while(horseGongzi.size())
{
std::string horseChoosed = GetGongziHorse(horseGongzi);
std::cout "第" i "场" std::endl;
std::cout "虚空公子派出了:" horseChoosed std::endl;
std::cout "田忌派出了:"
GetTianjiHorse(horseChoosed) std::endl;
i++;
std::cout std::endl;
}
std::cout "田忌无耻的赢了" std::endl;
getchar();
return 0;
}
相关问答
Q1: 在java中cyclibarriar和countdownlatch有什么区别
cyclibarriar 就是栅栏赛马游戏java代码,顾名思义赛马游戏java代码:就是一个拦截的装置。多个线程start后,在栅栏处阻塞住,一般定义栅栏的时候会定义有多少个线程。比如定义为4个,那么有三个线程到栅栏处,就阻塞住,如果没有第四个,就会一直阻塞,知道启动第四个线程到栅栏处,所有的线程开始全部进行工作。有点像赛马的例子。所有的赛马一个一个到起点,然后到齐了,在开始跑。
countdownlatch:初始化定义一个数字(整型),比如定义2,一个线程启动后在await处停止下来阻塞,调用一次countDown,会减一,知道countDown后变为0时的时候,线程才会继续进行工作,否则会一直阻塞。
自己写个赛马的程序,其实就什么都懂了。
Q2: JAVA代码
import java.util.Scanner;
public class TGT1 {
public static void main(String args[]){
int temp=input();
String level=print(temp);
System.out.println("您的等级为:");
System.out.println(level);
}
private static int input(){
System.out.println("请输入您的分数:");
int j=0;
while(true){
try{
Scanner scan=new Scanner(System.in);
j=scan.nextInt();
break;
}catch(Exception e){
System.out.println("您输入的不是数字");
continue;
}
}
return j;
}
private static String print(int score){
int i=(score-60)/20;
Level[] level=Level.values();
String name=null;
try{
name=level[i].name();
}catch(Exception e){
System.out.println("您的速度不在评级范围");
}
return name;
}
}
enum Level{
一星级,二星级,三星级,四星级,五星级,一钻级
}
//用枚举,轻松解决,第二题没看明白
Q3: java 多线程 赛马
package test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import sun.util.logging.resources.logging;
/**
* 2010-1-17 下午03:08:52 Piaolj
*/
public class Racing implements Runnable {
String str;
static Map horses = new TreeMap();// 定义一个全局赛马游戏java代码的Map存放5个马赛马游戏java代码的名字和时间
static int count = 0;// 用于判断县城是否全部结束
static boolean flag = true;// 后面用while(flag)判断count是否为0,如果有兴趣,可以起另外一个线程完成此任务
public Racing(String string) {
// TODO Auto-generated constructor stub
this.str = string;
}
public static void main(String[] args) {
Racing ra1 = new Racing("No.1 Horse");
Racing ra2 = new Racing("No.2 Horse");
Racing ra3 = new Racing("No.3 Horse");
Racing ra4 = new Racing("No.4 Horse");
Racing ra5 = new Racing("No.5 Horse");
Racing checkingThread = new Racing("checkingThread");
Thread t1 = new Thread(ra1);
Thread t2 = new Thread(ra2);
Thread t3 = new Thread(ra3);
Thread t4 = new Thread(ra4);
Thread t5 = new Thread(ra5);
t1.start();
t2.start();
t3.start();
t4.start();
t5.start();
while (flag) {
if (count == 0)// 所有线程结束
{
flag = false;
}
}
// 排序
List infoIds = new ArrayList(horses.entrySet());
Collections.sort(infoIds, new ComparatorMap.Entry() {
public int compare(Map.Entry o1, Map.Entry o2) {// 定义了比较的规则,因为这里是按map的value排序的
Long tmp = Long.parseLong(o1.getValue().toString())
- Long.parseLong(o2.getValue().toString());
return tmp.intValue();
}
});
System.out.println("输出马的名次:");
System.out.println();
for (int i = 0; i infoIds.size(); i++) {
String id = infoIds.get(i).toString();
System.out.println(id);
}
}
public void run() {
// TODO Auto-generated method stub
int CircuitLength = 1000;
int breakpoint = 200;
int tmpint = 200;
long Withtime;
count = count + 1;// 执行了一个线程,正在执行的线程数加1
// System.out.println(Thread.currentThread().getId());
for (int i = 0; i CircuitLength + 1; i++) {
long start = System.currentTimeMillis();
if (i == breakpoint) {
int sleeping = (int) (Math.random() * 5000);
try {
Thread.sleep(sleeping);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
breakpoint = breakpoint + tmpint;
}
if (i == CircuitLength) {
System.out.print(str + "\t" + "\t");
long end = System.currentTimeMillis();
Withtime = (end - start);
System.out.println("With time is:\t" + Withtime);
// 当每匹马跑完将马的时间的马的名称放入map中
horses.put(str, Withtime);
}
}
count = count - 1;// 执行完了一个线程,线程数减1
}
}
时间比较少,写的比较草,呵呵 加了点注释,要是有问题可以发短消息
输出结果:
No.4 Horse With time is: 888
No.3 Horse With time is: 3042
No.5 Horse With time is: 1921
No.2 Horse With time is: 4346
No.1 Horse With time is: 2831
输出马的名次:
No.4 Horse=888
No.5 Horse=1921
No.1 Horse=2831
No.3 Horse=3042
No.2 Horse=4346
Q4: 荒野大镖客2马克沁机枪代码
kzkzjzk.cbxmzm9464#mn
武器代码代码:GreedisAmericanVirtue效果:生成重型武器(需要报纸)。代码:Asimplelife,abeautifuldeath效果:生成普通武器。代码:Deathissilence效果:生成隐藏武器。代码:Historyiswrittenbyfools效果:生成枪械武器。代码:Abundanceisthedullestdesire效果:无限子弹(需要报纸)。
想必很多朋友都还不知道荒野大镖客2可以使用作弊码吧,而且作弊码在游戏中就能找到,估计大家都还不清楚吧,所以呢小编给大家带来了荒野大镖客2作弊秘籍中文一览,想要了解的不妨进来看看。全武器装备一览作弊码使用方法先按下游戏中的“暂停”按钮。选择“设置”菜单,然后按三角形(PS4)或Y(XBOX1)以访问隐藏的作弊菜单。然后在我们的作弊列表中输入你要用的RedDead2作弊代码。注:通过激活作弊,您将无法保存单人游戏进度,并收集单人游戏奖杯。武器代码代码:GreedisAmericanVirtue效果:生成重型武器(需要报纸)。代码:Asimplelife,abeautifuldeath效果:生成普通武器。代码:Deathissilence效果:生成隐藏武器。代码:Historyiswrittenbyfools效果:生成枪械武器。代码:Abundanceisthedullestdesire效果:无限子弹(需要报纸)。道具代码代码:IseekandIfind效果:解锁5级死亡之眼。代码:Istillseekmore效果:解锁4级死亡之眼。代码:Ishallbebetter效果:解锁3级死亡之眼。代码:Makemebetter效果:解锁2级死亡之眼。代码:Youflourishbeforeyoudie效果:完全恢复生命健康耐力及死亡之眼。代码:YouSeekMoreThanTheWorldOffers效果:恢复并强化健康、耐力、死亡之眼(需要报纸)。代码:Seekallthebountyofthisplace效果:增强健康、耐力、死亡之眼。代码:Theluckybestrongevermore效果:解锁无限耐力(需要报纸)。代码:VirtueUnearnedisnotvirtue效果:提高荣誉评级(需要报纸)。代码:Yourevelinyourdisgrace,Isee效果:降低荣誉评级(需要报纸)。代码:Balance.Allisbalance效果:保持中立。代码:Greedisnowavirtue效果:增加500$。代码:Betterthanmydog效果:无限距离唤马。代码:Afooloncommand效果:进入醉酒状态。
游戏相关代码:Youwantpunishment效果:提升通缉等级。代码:Balance.Allisbalance效果:降低通缉等级。代码:YouLongforSightbutSeeNothing效果:取消战争迷雾。
马相关代码代码:Run!Run!Run!效果:赛马。代码:Youareabeastbuiltforwar效果:战马。代码:Youwantmorethanyouhave效果:高级马。代码:Keepyourdreamssimple效果:马车和马。代码:Keepyourdreamslight效果:马车。代码:Thebestoftheoldways效果:驿站。代码:Youwantsomethingnew效果:随机生成任何马。代码:Wouldyoubehappierasaclown?效果:大篷车(需要报纸)。
解锁代码代码:Vanity.Allisvanity效果:解锁所有服装。代码:Eatofknowledge效果:学会所有配方。
关于赛马游戏java代码和java赛马程序的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。






