歡迎您光臨本站 註冊首頁

C++實現乒乓球比分判定

←手機掃碼閱讀     niceskyabc @ 2020-06-05 , reply:0

本文實例為大家分享了C++實現乒乓球比分判定的具體代碼,供大家參考,具體內容如下
 

編寫程序判斷乒乓球比賽的結果:輸入雙方比分,輸出誰勝誰負
 

此題的難度分3個級別

1、輸入的是一局比賽結束時的比分;
 2、輸入的不僅可能是一局比賽結束時的比分,還有可能是比賽進行過程中的比分;
 3、輸入任意兩個非負整數

下面選擇第三種難度完成:

  #include <iostream>    using namespace std;    int main() {    int player1, player2;      cout << "input two scores: " << endl;    cin >> player1 >> player2;      if (player1 < 0 || player2 < 0) cout << "wrong input" << endl;    else {      if (player1 == 11 && player2 < 10) cout << "player1 wins" << endl;      if (player2 == 11 && player1 < 10) cout << "player2 wins" << endl;      if (player1 < 11 && player2 < 11) cout << "not over" << endl;        if (player1 > 10 && player2 > 10) {        if ((player1 - player2) > 2 || (player2 - player1) > 2) cout << "wrong input" << endl;        if ((player1 - player2) == 2) cout << "player1 wins" << endl;        if ((player2 - player1) == 2) cout << "player2 wins" << endl;        if ((player1 - player2) <= 1 || (player2 - player1) <= 1) cout << "not over" << endl;      }    }      return 0;  }

 

試題分析:
 

①考察初學者的邏輯分析;
 ②考察基本語法if else的熟練程度;
 ③將日常生活作為程序設計的載體,寓教於樂;
 

補充:C++乒乓球比賽代碼

兩個乒乓球隊進行比賽,各處三人,甲隊為ABC,乙隊為XYZ,其中A不和X比賽,C不和X,Z,比賽,找出三隊賽手的名單

  #include "stdafx.h"  #include<iostream>  using namespace std;    int main()  {   char i, j, k;   for (i = &#x27;X&#x27;; i <= &#x27;Z&#x27;; i++) {   for (j = &#x27;X&#x27;; j <= &#x27;Z&#x27;; j++)   {    if (i != j) {    for (k = &#x27;X&#x27;; k <= &#x27;Z&#x27;;k++) {     if (i !=k&&j != k) {     if (i != &#x27;X&#x27;&&k != &#x27;X&#x27;&& k != &#x27;Z&#x27;) {      cout << "A-----" << i << endl << "B-----" << j << endl<< "C-----" << k << endl;     }     }    }    }   }   }   system("pause");    return 0;  }

[niceskyabc ] C++實現乒乓球比分判定已經有233次圍觀

http://coctec.com/docs/c/language/show-post-237034.html