java保龄球代码 保龄球 spare

http://zhidao.baidu.com/question/97094228.html跪求此JAVA的代码//花了不少时间!,为了程序好读,分了很多模块,多加点分啊,谢啦先
////为了便于调试,把从键盘输的数据放到了文件里,到属性--》C/C-》
//////编译器命令行选项里加/DF就可以使用文件了
////文件格式,百度死活不让我帖出来,说里边有广告,我汗 。
////注意student.txt里字符串后跟回车,整数后面跟空格就行了 。end结尾
////
////调用关系
////scoreofstus|--inputscore--showscore
////|--fingerout
////|--showstudent
class Student{ /* 学生信息类 */
String no; /* 学号 */
String name; /* 姓名 */
Date birthday; /* 出生日期 */
int score; /* 保龄球得分 */
};
class MyScore{
public static SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
Student stu[]=new Student[20];
Scanner sc=new Scanner(System.in);
int count=0;//学生数
//格式化显示分数信息
void showscore(int score[]){
System.out.printf("这一局的分数信息\n");
for(int i=1;i11;i){
System.out.printf(" %d\t",i);
}
for(int i=1;i10;i) {
System.out.printf("%-4d%-4d",1,2);
}
System.out.printf("1 2 3\n");
for(int i=0;i10;i) {
if(i==9) {
System.out.printf("%-3d",score[i*2]);
if(score[i*2]==10) {
System.out.printf("%-2c",'-');
System.out.printf("%-3d",score[i*2 2]);
}
else
if(score[i*2] score[i*2 1]==10) {
System.out.printf("%-2c",'-');
System.out.printf("%-3d",score[i*2 2]);
}
else {
System.out.printf("%-2d",score[i*2 1]);
System.out.printf("%-3c",'-');
}
break;
}
System.out.printf("%-4d",score[i*2]);
if(score[i*2]==10)System.out.printf("%-4c",'-');
else System.out.printf("%-4d",score[i*2 1]);
}
}
//输入分数
void inputscore(int score[]) {
int s1,s2,s3;
for(int i=0;i10;i) {
System.out.printf("Please input the score of the round-:\n",i 1);
Scanner sc=new Scanner(System.in);
s1=sc.nextInt();
if(s1!=10)
{
System.out.printf("Please input the score of the second goal in round-:\n",i 1);
s2=sc.nextInt();
}
else s2=0;
score[i*2]=s1;score[i*2 1]=s2;
if(i==9(s1 s2)==10)
{
System.out.printf("Please input the score of the third goal in round-:\n",i 1);
s3=sc.nextInt();
}
else s3=0;
score[20]=s3;
}
}
void inputscorefile(int score[]) {
int s1,s2,s3;
for(int i=0;i10;i) {
//System.out.printf("Please input the score of the round-:\n",i 1);
s1=sc.nextInt();
if(s1!=10) {
//System.out.printf("Please input the score of the second goal in round-:\n",i 1);
s2=sc.nextInt();
}
else s2=0;
score[i*2]=s1;score[i*2 1]=s2;
if(i==9(s1 s2)==10) {
//System.out.printf("Please input the score of the third goal in round-:\n",i 1);
s3=sc.nextInt();
}
else s3=0;
score[20]=s3;
}
showscore(score);
}
int fingerout(int score[]) {
int sum=0,s1,s2,s3;
for(int i=0;i10;i) {
if(score[i*2]==10||score[19] score[18]==10)sum =score[i*2] score[i*2 2];
sum =score[i*2 1];
}
return sum;
}
/////输入学生信息 ,年月日格式为2009-09-01
int inputstudent() {
int count=0;//学生总人数
while(true) {
System.out.printf("Please input the information of the student.'end' for End.学号 姓名 year month day(用enter键隔开各值):");
stu[count].no=sc.next();
if("end".equals(stu[count].no))break;
stu[count].name=sc.next();
try {
stu[count].birthday=sdf.parse(sc.next());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
count;
}
return count;
}
int inputstudentfile() throws FileNotFoundException {
Filefilein=new File("student.txt");
Scanner fsc=new Scanner(filein);
int count=0;//学生总人数
while(true) {
System.out.printf("Please input the information of the student.'end' for End.学号 姓名 year month day(用enter键隔开各值):");
stu[count].no=fsc.next();
if("end".equals(stu[count].no))break;
stu[count].name=fsc.next();
try {
stu[count].birthday=sdf.parse(sc.next());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
count;
}
return count;
}
//显示学生分数
void showstudent(File file) throws FileNotFoundException {
PrintWriter pw=new PrintWriter(file);
pw.printf("%-16s%-16s%-16s\n","学生学号","学生姓名","学生分数");
for(int i=0;icount;i)
pw.printf("%-16s%-16s%d\n",stu[i].no,stu[i].name,stu[i].score);
pw.close();
}
//显示学生分数 在consle
void showstudentToScreen(){
System.out.printf("%-16s%-16s%-16s\n","学生学号","学生姓名","学生分数");
for(int i=0;icount;i)
System.out.printf("%-16s%-16s%d\n",stu[i].no,stu[i].name,stu[i].score);
}
////求得并显示每个学生的分数的信息
void scoreofstus()
{
int score[]=new int[21];
for(int i=0;icount;i) {
System.out.printf("请输入学号为%s的学生的瓶数:\n",stu[i].no);
//inputscorefile(score);
inputscore(score);
stu[i].score=fingerout(score);
}
//显示所有学生的信息
System.out.printf("显示所有学生的信息\n");
showstudentToScreen();
}
void sort() {
////简单选择排序,汗
Student t=stu[0];
int min=0,j;
for(int i=0;icount;i)
{
for(j=0;jcount-i;j)
{
if(stu[min].scorestu[j].score)min=j;
}
j--;
t=stu[j];
stu[j]=stu[min];
stu[min]=t;
}
}
int search(String no) {
int i=0;
while(icountno.equals(stu[i].no))i;
if(i==count)
{
System.out.printf("not find");
return -1;
}
return i;
}
////////////////////////////////
public static void main(String args[]) throws FileNotFoundException {
MyScore myScore=new MyScore();
//count=inputstudentfile();
myScore.count=myScore.inputstudent();
myScore.scoreofstus();
myScore.sort();
myScore.showstudentToScreen();
File out=new File("data.dat");
myScore.showstudent(out);
while(true) {
String no;
int select=0;
System.out.printf("请选择:\n");
System.out.printf("0.显示学生信息:\n");
System.out.printf("1.查找:\n");
System.out.printf("2.退出\n");
select=myScore.sc.nextInt();
switch(select) {
case 0:myScore.showstudentToScreen();
break;
case 1: {
System.out.printf("请输入学号:");
no=myScore.sc.next();
int ii=myScore.search(no);
System.out.printf("%-16s%-16s%-16s\n","学生学号","学生姓名","学生分数");
System.out.printf("%-16s%-16s%d\n",myScore.stu[ii].no,myScore.stu[ii].name,myScore.stu[ii].score);
break;
}
case 2:System.exit(1);
default: {
System.out.printf("输入有误 , 请重新输入:\n");
break;
}
}
}
}
}
求C语言代码解释(保龄球记分程序)#include stdio.h //包含基本输入输出头文件
#define N 13 //宏定义13为N(N就是数字13)
struct { int n: /* 一轮内滚球次数 */
int f; /* 第一轮击倒柱数 */
int s; /* 第二次击倒柱数 */
int score; /* 本轮得分 */
int total; /* 至本轮累计总分 */
int m; /* 完成本轮得分计算, 还需要滚球次数 */
} s[N];//结构体
int ok = 0; /* 已完成完整计算的轮次数 */
int ball(int i, int n, int max) /* 完成一次滚//定义函数球,输入正确击倒柱数 */
{ if (i= 10) //如果 i小于等于 10
printf("输入第%d轮的第%d次滚球击倒柱数"), (=%d)//输出\n",i,n,max);
else //否则
printf("输入附加的第%d次滚球击倒柱数"),(=%d)//输出\n",c,max);
scanf("%d", d); 获得输入
if (d=0d=max) break; 如果 d大于等于0并且d小于等于max 中断
printf("不合理的击倒柱数, 请重新输入, \n"); //输出
}
if ( OK c-1) 如果ok小于 c-1
{ /* 对以前未完成计算的轮次分别计算得分与累计总分 */
for (j = ok 1; ji/j=i-1; j) j初始化为ok 1 每次循环加一,当j小于...错误
{a[j].scre =d; a[j].scre=a[j].scre d
if (--a[j].m==0) [j].m 减1 如果[j].m等于0
那么
{//错误
a[j]. total = (ji?a[j-1].total(:0/)j==1?0;a[j-1].total) a[j].score;ok=j/ok 1;}
a[j]. total =
}
}
return d; 返回d
}
main0
{int i,/*轮次 */ first.second k;
for(i=1; ok10;i)
{ /*处理第一次滚球 */
a[i].score = a[i].f=first = ball(i,1,10);
if (first==10) a[i].m=2;
a[i].n=1;
if (first10(i =10 || i==11ok10))
{ /*处理第二次滚球 */
a[i].score =a[i]. s=score=ball(i,2,10-first);
if(first second==10) a[i].m=1;
a[i].n/a[i].n=a[i].n 1/a[i].n=2 //错误
}
if (i =10first 10first second10)
{ a[i].total = (i1 ? a[i-1].total:0) a[i].score;
ok=1;
}
printf("各轮第一次得分");
for(k=1; k=i; k) printf("]",a[k].f);
printf("\n各轮第二次得分");
for(k=1; k= i; k)
if (a[k].n2) printf(" /");else printf("]", a[k].s);
printf("\n 各轮得分 ");
for (k=1; k= ok; k) printf("]", a[k].score);
printf("\n 累计总分 ");
for(k=1; k = ok; k) printf("]", a[k].total);
printf("\n\n");
}
}
跪求高手用JAVA编程#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "malloc.h"
typedef char ElemType;
#define OK 1
#define ERROR 0
#define OVER -1
typedef struct node
{
int number;
char name[20];
int chinese,math,english;
struct node *next;
} LinkList;
LinkList *InitList()
{
LinkList *H;
H=(LinkList *)malloc(sizeof(LinkList));
H-next=NULL;
return(H);
}
int Length_list(LinkList *H)
{
LinkList *p;
int j=0;
p=H;
while(p-next!=NULL)
{ p=p-next;
j;
}
return j;
}
void CreateList(LinkList *H,int n)
{
int i;
LinkList *s,*last;
char ch;
last=H;
for(i=1;i=n;i)
{ s=(LinkList *)malloc(sizeof(LinkList));
printf("\n请输入第%d个学生的学号:",i);
scanf("%d",s-number);
printf("\n请输入第%d个学生的姓名:",i);
scanf("%s",s-name);
printf("\n请输入第%d个学生的语文、数学和英语成绩:",i);
scanf("%d%d%d",s-chinese,s-math,s-english);
s-next=NULL;
last-next=s;
last=s;
}
}
LinkList *Locate(LinkList *H,int num)
{
LinkList *p;
p=H-next;
while(p!=NULLp-number!=num)
p=p-next;
return p;
}
LinkList *GetList(LinkList *H,int i)
{
LinkList *p;
int j=0;
p=H;
while(p-next!=NULL ji)
{
p=p-next;
j;
}
if(j==i)
return p;
else
return NULL;
}
int InsList(LinkList *p,LinkList x)
{
LinkList *s;
s=(LinkList *)malloc(sizeof(LinkList));
s-number=x.number;
strcpy(s-name,x.name);
s-chinese=x.chinese;
s-math=x.math;
s-english=x.english;
s-next=p-next;
p-next=s;
return OK;
}
int Ins_List(LinkList *H,int i,LinkList x)
{
LinkList *p;
p=GetList(H,i-1);
if(p!=NULL)
{
InsList(p,x);
return OK;
}
else
return ERROR;
}
int DelList(LinkList *p,LinkList *x)
{
LinkList *s;
s=p-next;
x-number=s-number;
strcpy(x-name,s-name);
x-chinese=s-chinese;
x-math=s-math;
x-english=s-english;
p-next=s-next;
free(s);
return OK;
}
int Del_List(LinkList *H,int i,LinkList *x)
{
LinkList *p;
p=GetList(H,i-1);
if(p!=NULLp-next!=NULL)
{
DelList(p,x);
return OK;
}
else
return ERROR;
}
out()
{
printf("\n*****************************************");
printf("\n请输入序号(0-4)选择要进行的操作:");
printf("\n0-------退出");
printf("\n1-------建立一个学生信息表");
printf("\n2-------插入一个学生信息");
printf("\n3-------删除一个学生信息");
printf("\n4-------查找一个学生是否在该学生信息表中");
printf("\n*****************************************\n");
}
void DisLinkList(LinkList *H)
{
LinkList *p;
printf("\n所有学生的信息如下:");
printf("\n 学号 姓名 语文 数学 英语\n");
p=H-next;
while(p!=NULL)
{
printf("-s潩漒n",p-number,p-name,p-chinese,p-math,p-english);
p=p-next;
}
}
void main()
{
LinkList *H,*p,*q,x;
int i,n,menux,flag,num;
//clrscr();
out();
H=InitList();
scanf("%d",menux);
do{switch(menux)
{
case 0: exit(0); break;
case 1:
printf("\n请输入要生成学生信息表的元素各数:");
scanf("%d",n);
CreateList(H,n);
printf("建立的学生信息表为:\n");
DisLinkList(H);
break;
case 2:
printf("\n请输入要插入的学生位置:");
scanf("%d",i);
printf("\n请输入要插入的学生信息:");
printf("\n请输入学生的学号:");
scanf("%d",x.number);
printf("\n请输入学生的姓名:");
scanf("%s",x.name);
printf("\n请输入学生的语文 数学和英语成绩:");
scanf("%d%d%d",x.chinese,x.math,x.english);
flag=Ins_List(H,i,x);
if(flag)
【java保龄球代码 保龄球 spare】{
printf("\n插入后的学生信息表为:");
DisLinkList(H);
}
break;
case 3:
printf("请输入要删除的学生的位置:");
scanf("%d",i);
flag=Del_List(H,i,x);
if(flag)
{
printf("\n删除第%d个学生后 , 表中信息为:",i);
DisLinkList(H);
}
break;
case 4:
printf("\n请输入查找的学生学号:\n");
scanf("%d",num);
if((q=Locate(H,num))!=NULL)
{
printf("\n在学生信息表中存在着学号为%d的学生!",num);
printf("\n学号 姓名 语文 数学 英语\n");
printf("-s潩?,q-number,q-name,q-chinese,q-math,q-english);
}
else
printf("\n在学生信息表中不存在着学号为%d的学生!",num);
break;
default:
printf("\n输入选项错误,请重新输入(0-4)!");
}
out();
scanf("%d",menux);
}while(1);
}
C的 你将就用吗
求高手帮忙写保龄球规则的c代码/*
* 作者: 陈先文
*
* 说明:
*楼主没有给定数据结构,我设计了一个,如果需要改动,我可以代劳,
*结构说明如下:
*
*用一个二维数组来保存分数 , score[i][j]表示第i局第j次击球的个数
*i从0至9,j为0或1. 另外,追加一个score10_3,以保存第10局的第3次击
*球 , 如果没有第三次击球 , 则置0即可
*
*若楼主需要以1至10为下标的 , 我可以代为修改程序 。
*/
//初始化
int score[10][2] = {0};
//保龄球记分
int calucateScore(int **score, int score10_3) {
....int result = 0;
....//前9次击球记分
....for(int i = 0; i9;i) {
........//第一击全倒
........if(score[i][0] == 10) {
............//下一局第一击也全倒
............if(score[i 1][0] == 10) {
................//若非第9局,则加20分和下两局的第一次击球得分
................//否则加上20分和第10局第二击的得分
................result= i8 ? (20score[i 2][0]) : (20score[9][1]);
............}
............//下一局第一击没有全倒, 加下一局的两次击球得分
............else {
................result= 10score[i 1][0]score[i 1][1];
............}
........}
........//第二击全倒
........else if(score[i][0]score[i][1] == 10) {
............//加上10分和下一局第一击得分
............result= 10score[i 1][0];
........}
........//其他
........else {
............result= score[i][1]score[i][2];
........}
....}
....//第10次击球,下标为9, 记分
....result= score[9][0]score[9][1];
....//若第10局有第三次击球 , 则加上该分数 。
....if(score[9][0]score[9][1] == 10)
........result= score10_3;
....return result;
}
跪求JAVA保龄球的JAVA代码/**
* 输出学生java保龄球代码的信息和进球信息到控制台
*/
private static void outPutStudentsToConsole(ListStudent stuList){
for (Student s:stuList) {
System.out.println(s.toString());
}
}
/**
* 输出学生java保龄球代码的信息和进球信息到文件中
*/
private static void outPutStudentsToFile(ListStudent stuList,String fileName){
PrintWriter pw=null;
try {
pw = new PrintWriter(new File("d:/" fileName));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
for (Student s:stuList) {
pw.print(s.toString());
pw.println();
}
pw.close();
}
/**
*按学号查找Student
*/
private static Student search(ListStudent stuList,String targetNo){
for (Student s:stuList) {
if(s.no.equals(targetNo)){
return s;
}
}
return null;
}
}
/**
*
* 1) 建立学生信息结构数组
2) 从键盘输入并显示每局java保龄球代码的球数
3) 求得并显示每名学生的分数
4) 按分数递减选择排序
5) 显示按分数排序后学生信息
6) 按学号查学生信息和分数(顺序查找法)
7) 将排序后的内容存为文件java保龄球代码,以后显示时直接从文件中调出而不用再执行排序算法 。
*
*/
java保龄球代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于保龄球 spare、java保龄球代码的信息别忘了在本站进行查找喔 。

    推荐阅读