/*
統一發票對獎器 這是用 DEV-C 開發的 DOS 提示符號的 程式源碼
*/
#include <stdio.h>
#include <string.h>
#define clrscr() system("CLS")
#define S 10
/*----------------------------------------------------------------------------*/
/* 畫面上的文字顯示 */
char text[8][5]={"特獎","頭獎","貳獎","參獎","肆獎","伍獎","陸獎","增開"};
char text3[]="請先輸入開獎號碼(0~9),輸入完請按下 Enter";
char text4[]="您輸入的開獎號碼中有不是數字的部分,請重新輸入";
char text5a[]="開/對獎號碼需要有 ";
char text5b[]=" 碼,您輸入的碼數只有 ";
char text5c[]=" 碼,請重新輸入";
char text6[]="請按任意鍵繼續 . . .";
char text7[]="請先輸入對獎號碼(0~9),輸入完請按下 Enter";
char text8[]="對獎";
char text9[]="恭喜你中";
/*----------------------------------------------------------------------------*/
/* 負責儲存開對獎號碼的字串陣列 */
char Special_award[9]={0};
char First_prize[3][9]={0};
char Six_award[2][4]={0};
char Chk_number[S][9]={0};
int level[10]={0};
char input[50]={0};
/*----------------------------------------------------------------------------*/
/* 列印畫面-開/對獎號碼 */
print_menu()
{
int i;
clrscr();
printf("%s : %-10s\t",text[0],Special_award);
for (i=0; i<3 ; i++)
{
printf("%s %d : %-10s\t",text[1],i+1,First_prize[i]);
if ( i==1 ) printf("\n");
}
for (i=0; i<2 ; i++) printf("%s%s %d : %-10s\t",text[7],text[6],i+1,Six_award[i]);
printf("\n\n");
for (i=0; i<S ; i++)
{
printf("%s %2d: %-10s\t",text8,i+1,Chk_number[i]);
chk_print(i);
}
printf("\n\n");
}
/*----------------------------------------------------------------------------*/
/* 列印畫面-中獎的類別 */
chk_print(int i)
{
if( level[i]>1 ) printf("%s",text9);
switch ( level[i] )
{
case 2:
printf("【%s%s】",text[7],text[6]);
break;
case 3:
printf("【%s】",text[6]);
break;
case 4:
printf("【%s】",text[5]);
break;
case 5:
printf("【%s】",text[4]);
break;
case 6:
printf("【%s】",text[3]);
break;
case 7:
printf("【%s】",text[2]);
break;
case 8:
printf("【%s】",text[1]);
break;
case 9:
printf("【%s】",text[0]);
break;
}
printf("\n");
}
/*----------------------------------------------------------------------------*/
/* 輸入對獎號碼 */
in_num_dtc(int x)
{
int i,j=0;
for ( i=0; i<S; i++ ) level[i]=-1;
for ( i=0; i<x; i++ )
{
while (j != 8)
{
print_menu();
printf("%s \n",text7);
printf("%s %d : ",text8,i+1);
scanf("%s",&input);
j=check_in(8);
}
j=0;
strcpy(Chk_number[i],input);
}
}
/*----------------------------------------------------------------------------*/
/* 輸入開獎號碼 */
in_num_src()
{
int i,j=0;
while (j != 8)
{
print_menu();
printf("%s \n",text3);
printf("%s : ",text[0]);
scanf("%s",&input);
j=check_in(8);
}
j=0;
strcpy(Special_award,input);
for ( i=0; i<3; i++ )
{
while (j != 8)
{
print_menu();
printf("%s \n",text3);
printf("%s %d : ",text[1],i+1);
scanf("%s",&input);
j=check_in(8);
}
j=0;
strcpy(First_prize[i],input);
}
for ( i=0; i<2; i++ )
{
while (j != 3)
{
print_menu();
printf("%s \n",text3);
printf("%s%s %d : ",text[8],text[7],i+1);
scanf("%s",&input);
j=check_in(3);
}
j=0;
strcpy(Six_award[i],input);
}
}
/*----------------------------------------------------------------------------*/
/* 檢查輸入的開/對號碼是否為"文字格式的數字" */
check_in(int k)
{
int i,j;
if ( strlen(input) == k )
{
for ( i=j=0; i<k; i++ )
{
if ( input[i]>=48 && input[i]<=57 ) j++;
else printf("\n\n %s",text4);
}
if ( j==k ) return j;
}
else
{
printf("\n\n%s%d%s%d%s",text5a,k,text5b,strlen(input),text5c);
}
printf("\n\n%s",text6);
getch();
return 0;
}
/*----------------------------------------------------------------------------*/
/* 檢查輸入的對號碼是否中獎 */
check(int x)
{
int i,j,k;
char chk1[9]="",chk2[9]="",chk3[4]="";
for ( i=0; i<x ;i++ )
{
if ( level[i]<0 )
{
if ( strcmp(Special_award,Chk_number[i])==0 )
{
level[i]=9;
continue;
}
strcpy(chk1,Chk_number[i]);
reverse(chk1);
for ( j=0; j<3; j++ ) chk3[j]=Chk_number[i][j+5];
for ( j=0; j<3; j++ )
{
if ( strcmp(First_prize[j],Chk_number[i])==0 )
{
level[i]=8;
continue;
}
strcpy(chk2,First_prize[j]);
reverse(chk2);
for ( k=0; k<8 ;k++)
{
if( k == 6 ) break;
if ( strncmp(chk1,chk2,7-k )==0 )
{
level[i]=7-k;
break;
}
}
}
for ( j=0; j<2; j++ )
if ( strcmp(Six_award[j],chk3)==0 ) level[i]=2;
}
}
}
/*----------------------------------------------------------------------------*/
/* 號碼反轉 */
reverse(char*sw2)
{
int i;
char sw1[9]="";
for ( i=0; i<8; i++ ) sw1[i]=sw2[7-i];
strcpy(sw2,sw1);
}
/*----------------------------------------------------------------------------*/
/* 選單的畫面 */
menu()
{
printf("\n1.輸入開獎號碼");
printf("\n2.對獎,1 次 1 個號碼");
printf("\n3.對獎,1 次 10 個號碼");
printf("\n4.離開");
printf("\n請選擇\功\能 1~4 : ");
}
/*----------------------------------------------------------------------------*/
/* 主方法 */
main()
{
char str;
int s;
do
{
print_menu();
menu();
s=getch();
s-=48;
switch(s)
{
case 1:
in_num_src();
print_menu();
break;
case 2:
in_num_dtc(1);
check(1);
print_menu();
break;
case 3:
in_num_dtc(S);
check(S);
print_menu();
break;
}
}while( s!=4 );
printf("\n\n%s",text6);
getch();
}
----------------------------------------------------------------------
下載原始碼 & 執行檔︰
http://rapidshare.de/files/12778082/LF12345678.rar.html
選項 3 的對號輸入的修正...
附註:野人獻醜...