作者loshihyen (瘦瘦)
看板ESOE-94
標題Re: [計程] 樂透開獎
時間Tue Apr 18 00:39:09 2006
※ 引述《aquila018 (旅行者)》之銘言:
我發現我每次寫出來的程式敘述和邏輯都不大一樣啦~"~
所以之前有看過我寫的用其他敘述或邏輯的人請再想想@@"
我是真的想不起我之前怎麼寫XD"
#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
int main(void){
int lot[6]={0}; //用來放六個號碼的陣列
int num[46]={0}; //用來記錄號碼是否取過的陣列,初始為0
int i;
srand(time(NULL));
for(i=0;i<6;){
lot[i]=(rand()%46)+1;
if(num[lot[i]-1]!=0)
continue;
else{
cout<<lot[i]<<" ";
num[lot[i]-1]++;
i++;
}
}
return 0;
}
想想看吧@@"
--
╭──╮ ╭──╮ ╭╮╭╮ ☆
╭╮╭──╮ ˙
│ │ │ │ ││││ ╭╮ │││ │ ˙
│ ☆ │ │ ☆
│ ││││ ││ │││ ☆ │ .·﹒
│╭╮│ ╰─╮│ │╰╯│ ││ │││╭╮│
╰╯╰╯ ╰╯ ╰──╰ ╰╯ ╰╯╰╯╰╯ ˙ ˙ ξAquila
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.203.51.12
#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
void main()
{
int a, i, j, num[7];//i, j 為號碼的順序
srand(time(NULL));//"srand"是用一個種子取亂數的函數,此時其種子為"time(NULL)"
。"time(NULL)"是"time.h"裡的函數,讀取時間。"NULL";此行輸出一個亂數"rand()"
num[0]=(rand()%46)+1;//使自srand函數得到亂數值介於1~46
for(i=1; i<7; ++i)
{ a=(rand()%46)+1;
for(j=0; j<i; ++j)
{
if(a==num[j])
{
i--;break;
}
else
num[i]=a;
}
}
cout<<"the lucky numbers this time are "<<num[0]<<", "<<num[1]<<",
"<<num[2]<<", "<<num[3]<<", "<<num[4]<<", "<<num[5]<<",\n and the special
number is "<<num[6];
}
--
痛啊>"<
○
︵︵\○
╱/| 我
刀都還沒拿出來你在痛什麼~"~
. . ﹎ ﹍﹍ ╱ ̄﹚
╱>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.167.240.195