编程题目如下:
第一题:
打保龄球是用一个滚球去打出十个站立的柱,将柱击倒。一局分十轮,每轮可滚球一次或多次,以击倒的柱数为依据计分。一局得分为十轮得分之和,而每轮的得分不仅与本轮滚球情况有关,还可能与后续一两轮的;滚球情况有关。即,某轮某次滚球击倒的柱数不仅要计入本轮得分,还可能会计入前一两轮得分。具体的滚球击柱规则和计分方法如下:
(1) 若某一轮的第一次滚球就击倒全部十个柱,则本轮不再滚球。(若是第十轮则还需另加两次滚球)。该轮得分为本次倒柱数 10 与以后两次滚球所击倒柱数之和。
(2) 若某一轮的第一次滚球未击倒十个柱,则可对剩下未倒的柱再滚球一次。如果这两次滚球击倒全部十个柱,则本轮不再滚球(若是第十轮则还需另加一次滚球),该轮得分为本次倒柱数10与以后一次滚球所击倒柱数之和。
(3) 若某一轮的两次滚球未击倒全部十个柱,则本轮不再继续滚球,该轮得分为这两次滚球击倒的柱数这和。
总之,若一轮中一次滚球或两次滚球击倒十个柱,则本轮得分是本轮首次滚球开始的连续三次滚球击倒柱数之和(其中有一次或两次不是本轮滚球)。若一轮内二次滚球击倒柱数不足十个,则本轮得分即为这两次击倒柱数之和。
以实例说明如下:
轮 1 2 3 4 5 6 7 8 9 10
各轮第一次得分10 10 10 7 9 8 8 10 9 10 8 #p#
各轮第二次得分/  /  /  2 1 1 2 /  1 /  2-
各 轮 得 分30 27 19 9 18 9 20 20 20 20
累 计 总 分30,57,76,85,103,112,132,152,172,192
要求:
1.使用你熟悉的程序语言(C#,java,javascript 之一)写一个程序可以方便的对保龄球运动项目进行记分;
界面布局合理,能直观的显示每次得分,每轮得分和累计得分的情况
2.分值录入操作合理,需要有必要的无效值判断处理(比如每次击球得分不会>10等等)
3.每场比赛结束后将本次比赛数据保存下来。(选择文件或者数据库均可),我昨天是用JAVA直接在控制台输出的,每次由我来输入击倒的数量,然后得分。我的代码算法太乱了,就不贴出来见笑了,大家还有写什么别的好办法吗?网上COPY的代码就不要来了,给点好的思路什么的,关于第2点验证和将最终数据保存成文件怎么弄啊~!希望大家一起交流下

解决方案 »

  1.   


    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Scanner;public class Bowling {    public static ArrayList<Round> rounds = new ArrayList<Round>();    public static void main(String[] args) {
    // init();//init() 为了调试
    input();
    countScore();
    countTatal();
    display();
        }    // ///////////////////////////////////////////////////////////////////////////////////////////
        public static void init() {
    // 读取数据过程 每次都大于0小于10;
    rounds.add(new Round(10, 0));
    rounds.add(new Round(10, 0));
    rounds.add(new Round(10, 0));
    rounds.add(new Round(7, 2));
    rounds.add(new Round(9, 1));
    rounds.add(new Round(8, 1));
    rounds.add(new Round(8, 2));
    rounds.add(new Round(10, 0));
    rounds.add(new Round(9, 1));
    rounds.add(new Round(10, 8));
    if (rounds.get(9).firstNumber == 10)
        rounds.add(new Round(2, 0));
    // 为了简化计算,添加虚拟轮数,实际上不存在;;    }    // ///////////////////////////////////////////////////////////////////////////////////////////
        public static void input() {// 控制台输入,模拟击柱数
    Scanner scanner = new Scanner(System.in);
    String regex = "\\d|10";
    String temp = null;
    int firstNumber = 0, secondNumber = 0; for (int i = 0; i < 10; i++, firstNumber = 0, secondNumber = 0) {
        temp = "";
        System.out.println("第" + (i + 1) + "轮第一次击柱数");
        while (!(temp = scanner.nextLine()).matches(regex))
    ;
        ;
        firstNumber = Integer.parseInt(temp);
        if (firstNumber != 10) {
    System.out.println("第" + (i + 1) + "轮第二次击柱数");
    while (!(temp = scanner.nextLine()).matches(regex))
        ;
    ;
    secondNumber = Integer.parseInt(temp);
        }
        rounds.add(new Round(firstNumber, secondNumber));
    }
    Round round = rounds.get(9);// 第9轮
    System.out.println("倒数第二次击柱数");
    while (!(temp = scanner.nextLine()).matches(regex))
        ;
    ;
    round.secondNumber = Integer.parseInt(temp);
    if (round.firstNumber == 10
    || round.firstNumber + round.secondNumber == 10) {
        System.out.println("最后一次击柱数");
        while (!(temp = scanner.nextLine()).matches(regex))
    ;
        ;
        firstNumber = Integer.parseInt(temp);
        rounds.add(new Round(firstNumber, 0));
    }    }    // ///////////////////////////////////////////////////////////////////////////////////////////
        public static void display() {//输出到控制台和文件
    StringBuffer sb = new StringBuffer();
    sb.append("轮数:        ");
    for (int i = 1; i <= 10; i++) {
        sb.append(String.format("%5d", i));
    }
    sb.append("\r\n第一次击球得分:");
    for (int i = 0; i < 10; i++) {//
        sb.append(String.format("%5d", rounds.get(i).firstNumber));
    }
    sb.append("\r\n第二次击球得分:");
    for (int i = 0; i < 10; i++) {
        Round round = rounds.get(i);
        if (round.firstNumber == 10)
    sb.append(String.format("%5d", rounds.get(i).secondNumber));
        else
    sb.append("    /");
    }
    sb.append("\r\n本轮得分:     ");
    for (int i = 0; i < 10; i++) {
        sb.append(String.format("%5d", rounds.get(i).score));
    }
    sb.append("\r\n累计得分:     ");
    for (int i = 0; i < 10; i++) {
        sb.append(String.format("%5d", rounds.get(i).total));
    }
    sb.append("\r\n");
    System.out.println(sb.toString());
    try {
        BufferedWriter bw = new BufferedWriter(new FileWriter(
        "c:/Bowling.txt"));
        bw.write(sb.toString());
        bw.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
        }    // ///////////////////////////////////////////////////////////////////////////////////////////    public static void countScore() {// 统计各轮分数
    Round round = rounds.get(9);// 第9轮
    if (round.firstNumber == 10
    || round.firstNumber + round.secondNumber == 10)
        round.score = round.firstNumber + round.secondNumber
        + rounds.get(10).firstNumber;
    else
        round.score = round.firstNumber + round.secondNumber;
    // ---------------------------------------------------------------------------------
    for (int i = 8; i >= 0; i--) {// 第8轮,第7轮...第0轮
        round = rounds.get(i);
        Round tempRound = rounds.get(i + 1);
        if (round.firstNumber == 10) {// 首次分数为10
    if (tempRound.firstNumber == 10)
        round.score = round.firstNumber + tempRound.firstNumber
        + rounds.get(i + 2).firstNumber;
    else
        round.score = round.firstNumber + tempRound.firstNumber
        + tempRound.secondNumber;
        } else if (round.firstNumber + round.secondNumber == 10)// 前两次分数为10
    round.score = round.firstNumber + round.secondNumber
    + tempRound.firstNumber;
        else
    round.score = round.firstNumber + round.secondNumber;// 首次分数为10
    }
        }    // ///////////////////////////////////////////////////////////////////////////////////////////
        public static void countTatal() {// 统计前n轮的累加分数
    rounds.get(0).total = rounds.get(0).score;// 第0轮
    for (int i = 1; i < 10; i++)
        // 第1轮 第2轮...第9轮
        rounds.get(i).total = rounds.get(i).score + rounds.get(i - 1).total;
        }}class Round {
        private static int counter = 0;// 计数器
        private final int id = counter++;// id 代表 第id轮,id = 0,1,2,3,4,5,6,7,8,9
    // (可能有10)
        int firstNumber;// 本轮击倒第一次击倒柱数
        int secondNumber;// 本轮击倒第二次击倒柱数
        int score;// 本轮得分
        int total;// 至本轮累计总分    public Round(int number, int secondNumber) {
    this.firstNumber = number;
    this.secondNumber = secondNumber;
        }
    }
    /*
    第1轮第一次击柱数
    10
    第2轮第一次击柱数
    10
    第3轮第一次击柱数
    10
    第4轮第一次击柱数
    7
    第4轮第二次击柱数
    2
    第5轮第一次击柱数
    9
    第5轮第二次击柱数
    1
    第6轮第一次击柱数
    8
    第6轮第二次击柱数
    1
    第7轮第一次击柱数
    8
    第7轮第二次击柱数
    2
    第8轮第一次击柱数
    10
    第9轮第一次击柱数
    9
    第9轮第二次击柱数
    1
    第10轮第一次击柱数
    10
    倒数第二次击柱数
    8
    最后一次击柱数
    2
    轮数:            1    2    3    4    5    6    7    8    9   10
    第一次击球得分:   10   10   10    7    9    8    8   10    9   10
    第二次击球得分:    0    0    0    /    /    /    /    0    /    8
    本轮得分:        30   27   19    9   18    9   20   20   20   20
    累计得分:        30   57   76   85  103  112  132  152  172  192*/
      

  2.   

    + 我也是这么感觉的,不要用控制台,用GUI好像很容易吧,难道是我眼高手低?
      

  3.   

    《敏捷软件开发:原则、模式与实践 》  第六章 一次编程实践保龄球记得的结对编程。。去下载看看吧
    加上PDF下载地址吧。
    http://download.csdn.net/detail/java719904878/1025509(5分)http://ishare.iask.sina.com.cn/f/5410737.html?from=like(0分)
     
      

  4.   

    这题目没什么难度吧.
    搞两个数组,数组1存放21个元素,
    数组1初始化为-1;
    数组2存放每轮分数,
    i为数组下标,
    如果扔得分10个,i++再进入下一个循环(即空出一个位置);扔完之后统计分数;
    判断奇数位
    1如果不为负数,
       如果加上前一个偶数位的值为10,就加上后一次偶数位的值.(偶数位必有数据,奇数位不一定)
       否则此轮得分为奇数位加偶数位的和.
    2如果奇数位为负数
       说明得分为10,可以加后面的两个得分,
       用循环加上后面两个的得分.
    感觉实现很简单,就写一下得了...#include <stdio.h>
    int main(int argc, char const* argv[])
    {
    int i,j;
    int iround[21];
    int iscore[10],icount; for(i=0; i<21; i++)
    {
    scanf("%d", &iround[i]);
    if(iround[i] == 10 && i%2==0)
    {
    printf("%d ", iround[i]);
    i++;
    iround[i]=-1;
    }
    printf("%d ", iround[i]);
    }
    printf("\n");
    for(i=0; i<20; i++)
    {
    if(i%2 != 0)
    {
    if(iround[i] >= 0)
    {
    if(iround[i]+iround[i-1] == 10) 
    {
    iscore[i/2] = iround[i] + iround[i-1] + iround[i+1];
    }
    else
    {
    iscore[i/2] = iround[i] + iround[i-1];
    }
    }
    else
    {
    for(iscore[i/2] = icount = 0, j = i; icount < 2 && j<21; j++)
    {
    if(iround[j] >= 0)
    {
    icount++;
    iscore[i/2] += iround[j];
    }
    }
    iscore[i/2] += iround[i-1];
    }
    }
    }
    for(i = 0; i<10; i++)
    {
    printf("%d ", iscore[i]);
    }
    printf("\n");
    }
      

  5.   

    看了jihen兄的代码,顿悟,释然 ...
      

  6.   

    还有输出 我的程序 在eclipse中输出格式  和  在文件中输出格式  有点区别  希望高手无私指点,怎么消除这种差别
      

  7.   

    好 我很 慌张 刚学c++ 压力很大 
    小弟是自学 刚学过vb 感觉b很方便 但是大家都用 vc 我就又过来学 vc了 嗨 
      

  8.   

    #include<time.h>
    #include<iostream>using namespace std;//a、b、r分别记录第一次投球得分、第二次投球得分、每轮投球得分,数组初始化为0
    int a[12], b[11], r[10], i;void main()
    {
    srand((int)time(0)); //随机产生投球分数
    for (i = 0; i < 10; i++)
    {
    int q = rand()%11;
    if (q == 10)
    {
    a[i] = 10;
    b[i] = 0;
    if (i == 9)
    {
    a[i+1] = rand()%11;
    if (a[i+1] == 10)
    {
    a[i+2] = rand()%11;
    }
    else
    {
    b[i+1] = rand()%(11-a[i+1]);
    }
    }
    }
    else
    {
    a[i] = q;
    b[i] = rand()%(11-q);
    if(i == 9)
    {
    if (a[i] + b[i] == 10)
    {
    a[i+1] = rand()%11;
    }
    }
    }
    } //统计每轮的分数
    for (i = 0; i < 10; i++)
    {
    if (a[i] == 10)
    {
    if (a[i+1] == 10)
    {
    r[i] = 20 + a[i+2];
    }
    else
    {
    r[i] = 10 + a[i+1] + b[i+1];
    }
    }
    else
    {
    r[i] = a[i] + b[i];
    if (r[i] == 10)
    {
    r[i] += a[i+1];
    }
    }
    } //输出分数
    cout<<"各轮第一次得分:"<<endl;
    for(i = 0; i < 12; i++)
    {
    cout<<a[i]<<" ";
    }
    cout<<endl<<endl;
    cout<<"各轮第2次得分:"<<endl;
    for(i = 0; i < 11; i++)
    {
    cout<<b[i]<<" ";
    }
    cout<<endl<<endl;
    cout<<"各轮得分:"<<endl;
    for(i = 0; i < 10; i++)
    {
    cout<<r[i]<<" ";
    }
    cout<<endl<<endl;
    cout<<"累计总分:"<<endl;
    int t = 0;
    for(i = 0; i < 10; i++)
    {
    t += r[i];
    cout<<t<<" ";
    }
    cout<<endl<<endl;}
      

  9.   

    终于看懂题目要求了,编了一个:#include<stdio.h>
    int main()
    {
    int scor1[11] = {0};//第一轮得分
    int scor2[11] = {0};//第二轮得分
    int scor3[10] = {0};//每轮得分
    int total[10] = {0};//总得分 int i = 0;

    for(i=0;i<11;)
    {
    printf("input the %d score\n",i+1);
    scanf("%d,%d",&scor1[i],&scor2[i]);
    if(scor1[i]>10 || (scor1[i]+scor2[i]>10))
    {
    printf("error!\n");
    continue;
    }
    i++;
    } for(i=0;i<10;i++)
    {
    if(10 == scor1[i])//本轮第一次击倒全部10个球
    {
    if(10 == scor1[i+1])
    {
    scor3[i] = scor1[i] + scor1[i+1] +scor1[i+2];
    }
    else
    {
    scor3[i] = scor1[i] + scor1[i+1] +scor2[i+1];
    }
    }
    else//没有击倒全部10个球
    {
    if(10 > (scor1[i] + scor2[i]))
    {
    scor3[i] = scor1[i] + scor2[i];
    }
    else if(10 == (scor1[i] + scor2[i]))
    {
    scor3[i] = scor1[i] + scor2[i] + scor1[i+1];
    }
    else
    {
    printf("score error!\n");
    return -1;
    }
    }
    if(!i)
    {
    total[i] += scor3[i];
    }
    else
    {
    total[i] += total[i-1]+scor3[i];
    }
    }

    for(i=0;i<10;i++)
    {
    printf("total[%d]=%d\n",i,total[i]);
    }
    return total[9];
    }