Zclub討論區 Z板

 找回密码
 註冊
搜索
楼主: 萬能版zclub

救命啊~~~C++

[复制链接]
发表于 2004-6-20 15:00:14 | 显示全部楼层

回覆給:當軌道車遇上障礙物

眼睛一亮~~感謝~~解決我多年來的疑問了~~

回覆給:大丙 FF-22

丙大的方法推一票~~

聽到丙大想法,突然想到,可以模擬真的開樂透的方法,
就是開了一顆球之後,剩下的球繼續攪,然後再開,一值開開開~~

// Lotto2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>

//樂透幾個數字
#define lotto_number 6
//樂透最大數
#define max_number 6
//因為想要把int當保險套用『想要就用~用完就丟@@|||』
#define for if(0);else for

int main(int argc, char* argv[])
{
 int lotto[max_number];
 int lotto_1,tmp;
 //設定亂數的SEED,讓假亂數變真亂數。
 srand( (unsigned)time( NULL ) ); 
 do{
  printf("按六下模擬開獎囉~~\n");
  //初始化
  for (int i=0;i<max_number;i++)
   lotto[i]=i+1;
  //開始開獎
  for (int i=0;i<lotto_number;i++)
  {
   //開始攪囉,攪到爽
   for (int j=0;!_kbhit();j++)
   {
    j=j%(max_number-i);
    lotto_1=rand()%(max_number-i);
    tmp=lotto[lotto_1];
    lotto[lotto_1]=lotto[j];
    lotto[j]=tmp;
   }
   _getch();
   //秀出亂數
   printf("%4d",lotto[lotto_number-i-1]);
  }
  //提示是否要再來一次
  printf("\n再『踢』一次嗎~? \nEsc不踢\n任意鍵繼續踢\n");
  //如果是按下ESC就跳出
 }while((getch())!=27);
 return 0;
}

回复

使用道具 举报

发表于 2004-6-20 21:12:40 | 显示全部楼层

回覆給:特洛瓦
回覆給:陳
回覆給:當軌道車遇上障礙物
請問大大們要如何讓下面的程式碼自動所產生的數字不重覆>>>還要每4組要跳一行^^"(我已經盡力了)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 6
void print_matrix(int a[]),bubble(int a[]);
int main(void)
{
   int i,data[6],a,j;
   srand((unsigned)time(NULL));
   printf("請輸入要購買的組數");
   scanf("%d",&a);
   for(j=0;j<a;j++)
   {
   for(i=0;i<6;i++)
    {
     data[i]=(rand()%42+1);
    }
     bubble(data);
     print_matrix(data);
   
    }
   system("PAUSE");
   return 0;
}
void print_matrix(int a[])
{
   int i;

   for(i=0;i<SIZE;i++)
    printf("%d ",a[i]);
   printf("\n");
   return;
}

void bubble(int a[])
{
   int i,j,temp;
 
   for(i=1;i<SIZE;i++)
      for(j=0;j<(SIZE-1);j++)
         if(a[j]>a[j+1])
         {
            temp=a[j];
            a[j]=a[j+1];
            a[j+1]=temp;
         }
   return;
}

回复

使用道具 举报

发表于 2004-6-20 21:17:07 | 显示全部楼层

回覆給:特洛瓦
回覆給:陳
回覆給:當軌道車遇上障礙物
請問大大們要如何讓下面程式第2個數字輸入跟第1個數字一樣時會叫你在重新輸入第2個,第3個數字則不能跟第1、2數字一樣否則重新輸入以此類推幫我看看需要加些什麼感恩^^"
#include <stdio.h>
#include<stdlib.h>

int main(void)
{
 int a[6], i;

 for(i=1; i<=6; i++)
 {
 do
 {
 printf("請輸入第%d數字(1~42)\n",i);
 scanf("%d",&a[i]);

 }
 while (a[i]<1 || a[i]>42);
  printf("你所輸入第%d數字為%d\n",i,a[i]);
 }
 
 system("PAUSE");
 return 0;
}

回复

使用道具 举报

发表于 2004-6-20 21:51:34 | 显示全部楼层

我寫>NET的程式碼給你~~~~~~~~
妳想要DOS版的!?
還是WINDOWS版的!?  ^.^
不說我直接寫WINDOWS版的唷!

回复

使用道具 举报

发表于 2004-6-20 21:56:36 | 显示全部楼层
回覆給:真夜
不懂
回复

使用道具 举报

发表于 2004-6-20 21:57:57 | 显示全部楼层

妳是想要SHOW DOS模式的還是SHOW WINDOWS模式的呢?
我用.NET來編譯程式唷!

回复

使用道具 举报

发表于 2004-6-20 21:59:29 | 显示全部楼层
回覆給:真夜
你有奇摩或是MSN即時通嗎~~
我奇摩:cow890015@yahoo.com.tw
MSN:cow890015@yahoo.com.tw
回复

使用道具 举报

发表于 2004-6-20 23:30:07 | 显示全部楼层
回覆8 國:
第一個問題我回答了喔。
輸入六個阿拉伯數字,重複會顯示"TRY AGAIN"
第二個問題特洛瓦幫你回答了。
提供一個以空間換時間的方法~~


原碼有些許差異,其實可以擷取精要改改就可以套用到你的程式碼內。
建議你上面的文章再看一下。:-)
回复

使用道具 举报

发表于 2004-6-20 23:32:36 | 显示全部楼层
回覆真夜:
8 國連console mode coding都有問題,你卻還想給他.NET程式碼?
回复

使用道具 举报

发表于 2004-6-20 23:57:15 | 显示全部楼层

最近常血的是.net~~~~~~~~
換個血我還比較不會寫呢

回复

使用道具 举报

发表于 2004-6-21 12:33:27 | 显示全部楼层

回覆給:丫國

你的問題
1.每N個換行
2.檢查是否有重複
3.還有之前的包牌

p.s.我看規則是樂透沒有順序之分,只要號碼有出來就可以,我不清楚因為我沒在玩,我是在網路上看到的,所以我依照這規則來寫。

『凡投注購券者所選之六個號碼中,有三個以上(含三個)號碼與開出之六個號碼相同者,便為中獎,並可依法請領獎金。』--資料來源--http://www.roclotto.com.tw/

下面這個程式包含了你的這些問題,
換行的話基本上用取餘數的方式解決,在程式中有,你可以善加利用。
是否有重複的話,基本上我是用迴圈往回檢查,參考參考。


// Lotto3.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <conio.h>
#include <stdio.h>
#include <math.h>
#include <process.h>

//因為想要把int當保險套用『想要就用~用完就丟@@|||』
#define for if(0);else for
//樂透的最大數字
#define max_lotto_number 46
//樂透個數
#define lotto_number 6

int dec_bin(int max_number,int bin_array[]);

int main(int argc, char* argv[])
{
 int bin_array[max_lotto_number]={0};
 int all_lotto,lotto_array[max_lotto_number];
 //取得使用者想要包牌的個數
 printf("請輸入欲包牌的數7~46...");
 scanf("%d",&all_lotto);
 //取得使用者想要包的號碼
 printf("請輸入想包的號碼...");
 for(int i=0;i<all_lotto;i++)
 {
  scanf("%d",&lotto_array[i]);
  //檢查是否重複
  for(int j=0;j<i;j++)
  {
   if(lotto_array[j]==lotto_array[i])
   {
    printf("號碼已經輸入過,請重新輸入\n");
    i--;
   }
  }
 }
 //清除螢幕
 system("cls");
 //秀出最後使用者想要包的牌
 printf("以下為您包的牌\n");
 for(int i=0;i<all_lotto;i++)
  printf("%4d",lotto_array[i]);
 //計算包牌的結果
 printf("\n以下為包牌結果----------------------------\n");
 int cntr=0;
 for(int i=0;i<pow(2,all_lotto);i++)
 {
  if(dec_bin(i,bin_array)==lotto_number)
  {
   for(int j=0;j<all_lotto;j++)
   {
    if(bin_array[j]==1)
     printf("%4d",lotto_array[j]);
   }
   printf("\n");
   cntr++;
   //N個停下來一次
   if(cntr%10==0)
   {
    printf("按任意鍵繼續\n");
    getch();
   }
  }
 }
 printf("共%6d牌\n任意鍵結束",cntr);
 getch();
 return 0;
}

int dec_bin(int dec_number,int bin_array[])
{
 int sum=0;
 for(int i=0;dec_number!=0;i++,dec_number=dec_number/2)
 {
  sum=sum+(dec_number%2);
  bin_array[i]=(dec_number%2);
 }
 return sum;
}

回复

使用道具 举报

发表于 2004-6-21 14:57:49 | 显示全部楼层
回覆給:特洛瓦
你的程式不錯唷~~~可是包牌8個數字應該是28個號碼^^"
回复

使用道具 举报

发表于 2004-6-21 15:53:08 | 显示全部楼层
回覆給:丫國

是28沒錯阿~~
我最後有印出來總共幾附牌阿~~是28阿~~
我剛有試過說~~我中間有每10停下來一次~~
是不是你沒有注意到阿~~
回复

使用道具 举报

发表于 2004-6-21 15:59:00 | 显示全部楼层
回覆給:丫國

阿~~還是你是說我誤會包牌的意思~~
我是參考下面的規則~~
http://qa.pcuser.com.tw/modules/newbb/viewtopic.php?viewmode=flat&topic_id=2479&forum=26

因為我想說~~包牌應該就是把所有組合排起來~~
難道~~是我誤會了嗎~~
請高手明示~~
回复

使用道具 举报

发表于 2004-6-21 16:11:54 | 显示全部楼层
回覆給:特洛瓦
我忘了看下面了^^"~~~~~~拍謝!!你寫的是對的^0^~~感恩!!
回复

使用道具 举报

发表于 2004-6-22 11:16:57 | 显示全部楼层

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 6
void print_matrix(int a[]),bubble(int a[]);
void RunNemberCeeate();
int RunNember();
bool TestNumber(int *data, int j);

int main(void)
{
   int data[6],a;
   int data2[8];

   RunNemberCeeate();

   printf("1,自選邊號模式 2,電腦選號模式 3,包排模式\n");
   printf("請輸入妳所要的的樂透模式!");
   scanf("%d",&a);
// 自選模組!
    if(a==1){
        for (int i = 0; i < 6; i++){
            printf("請輸入你所需要的號碼:");
            scanf("%d",&a);
            //  輸入必須在1~42之間!
            if(a>=1 && a<=42 ){
                data[i] = a;
                //      清除重複的號碼
                if (TestNumber( data, i)){
                   printf("輸入的號碼跟之前的重複,請重新輸入!\n");
                   i--;
                }
            }else{
               printf("輸入的號碼不在1~42之間,請重新輸入!\n");
               i--;
            }
        }
        //  輸出銀幕!
        bubble(data);
        print_matrix(data);
    }
//  自動產生模組!
    else if(a==2){
//        clrscr();
        printf("請輸入要購買的組數");
        scanf("%d",&a);
        for(int j = 0; j<a; j++ ){
            for(int i = 0; i<6; i++ ){
                data[i] = RunNember();
                if (TestNumber( data, i))
                   i--;
            }
        bubble(data);
        print_matrix(data);
        }
    }
//  包排模組!
    else if(a==3){
//      輸入8個號碼!
        for (int i = 0; i < 8; i++){
            printf("請輸入你所需要的號碼:");
            scanf("%d",&a);
            //  輸入必須在1~42之間!
            if(a>=1 && a<=42 ){
                data[i] = a;
                //      清除重複的號碼
                if (TestNumber( data, i)){
                   printf("輸入的號碼跟之前的重複,請重新輸入!\n");
                   i--;
                }
            }else{
               printf("輸入的號碼不在1~42之間,請重新輸入!\n");
               i--;
            }
        }
//      處理秀出28組號碼
        for(int j = 0; j<28; j++){
            for(int i = 0; i<8; i++){
                data[]
            }
        }
    }

   system("PAUSE");
   return 0;
}

// 判別是否重複!
bool TestNumber(int *data, int j){
    int i;

    i = data[j];
    for (int l = 0; l < j; l++){
        if (data[l] == i)
           return true;
    }
    return false;
}

//  亂數產生!
int RunNember(){
    return ((rand()%42)+1);
}
//  亂數種子
void RunNemberCeeate(){
   srand((unsigned)time(NULL));
}

void print_matrix(int a[])
{
   int i;

   for(i=0;i<SIZE;i++)
    printf("%d ",a[i]);
   printf("\n");
   return;
}

void bubble(int a[])
{
   int i,j,temp;
 
   for(i=1;i<SIZE;i++)
      for(j=0;j<(SIZE-1);j++)
         if(a[j]>a[j+1])
         {
            temp=a[j];
            a[j]=a[j+1];
            a[j+1]=temp;
         }
   return;
}

剩包牌沒寫~~~~寫的不是很好說!

回复

使用道具 举报

发表于 2004-6-23 18:03:31 | 显示全部楼层
回覆給:丫國

請問~~你是育達技術學院的嗎~~
我同學問的問題~~跟你一磨一樣~~
是不是還要計算一組50塊錢總共多少錢~~
是不是包牌9組以上加分~~
挖哩勒~~如果同效的話真是太巧了~~
如果不同學題目還一樣~~那真是太不可思議了~~
回复

使用道具 举报

发表于 2004-6-23 19:32:42 | 显示全部楼层
回覆給:特洛瓦
哇~~勒@@">>>>>他是資一B的嗎~~~~順便跟我說一下名字<<<<<肯定是我們班我的msn:cow890015@yahoo.com.tw
回复

使用道具 举报

发表于 2004-6-23 20:03:21 | 显示全部楼层
噗~~~~~~~原來寫完還有加分呀!
~~~~~~~~~~~~~~~~~.......
回复

使用道具 举报

发表于 2004-6-23 21:01:49 | 显示全部楼层
回覆給:丫國

其實她是我朋友的朋友~~我只知道她是女生~~
然後阿~~我把我所有原始碼都寄給她了~~
外加整合~~彩卷記錄~~開獎~~對獎~~都給她了說~~
(我還沒有PO上來的程式碼~~)
這樣你們程式會不會太多一樣的地方阿~~
到時候會不會被老師說~~說~~~~~~~~~
說你們兩個有一腿阿~~@@"
回复

使用道具 举报

Yahoo
您需要登录后才可以回帖 登录 | 註冊

本版积分规则

手機版|Archiver|Z板 Sitetag 訪客統計

GMT+8, 2024-10-12 04:32 , Processed in 0.098472 second(s), 14 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表