Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /****************************************/
- /** 20150409 Rabit Running (Not Class) **/
- /** Maker : Yan **/
- /** E-Mail : [email protected] **/
- /** Date : 2015/04/09 pm.08:30 **/
- /****************************************/
- //C input / output library
- #include <stdio.h>
- #include <stdlib.h>
- #include <iostream> //C++ Input / Output library
- #include <iomanip> //To format output --> [setw()]
- using namespace std;
- //Use for Sleep() --> *mark on [Delay]
- #include <Windows.h>
- //Use for random the [random number]
- #include <time.h>
- int main(int argc, char const *argv[]){
- cout << "Enter a nuber of rabit: ";
- int rabitNum = 0;
- if (scanf_s("%d", &rabitNum) <= 0)
- return 0;
- else {
- int tripLenght = 0;
- cout << "Enter a number of trop lenght: ";
- if (scanf_s("%d", &tripLenght) == 0)
- return 0;
- else{
- //Make a array to record now rabit aleady run lenght, and make refresh
- int *rabitAlreadyRun = (int *)malloc(rabitNum * sizeof(int));
- for (int i = 0; i < rabitNum; i++)
- rabitAlreadyRun[i] = 0;
- //Random the [random number]
- srand(time(NULL));
- while (1){
- system("cls");
- //Rabit run
- for (int i = 0; i < rabitNum; i++)
- rabitAlreadyRun[i] += rand() % 3;
- //Show on form
- for (int i = 0; i < rabitNum; i++){
- cout << "Rabit " << setw(2) << (i + 1) << " ||";
- for (int j = 0; j < ((tripLenght <= rabitAlreadyRun[i]) ? tripLenght : rabitAlreadyRun[i]); j++)
- cout << "#";
- for (int j = 0; j < ((tripLenght <= rabitAlreadyRun[i]) ? -1 : (tripLenght - rabitAlreadyRun[i])); j++)
- cout << " ";
- cout << "||" << endl;
- }
- //Check
- for (int i = 0; i < rabitNum; i++){
- if (rabitAlreadyRun[i] >= tripLenght){
- cout << endl << "Rabit " ;
- for (int j = 0; j < rabitNum; j++){
- if (rabitAlreadyRun[j] >= tripLenght)
- cout << j + 1 << ", ";
- }
- cout << "\b\b" << " Win !" << endl;
- free(rabitAlreadyRun);
- return 0;
- }
- }
- //Daley
- Sleep(0.5 * 1000);
- }
- }
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment