最后4位數(shù)字中的前兩位表示當(dāng)?shù)嘏沙鏊木幋a;
成都創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比東昌網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式東昌網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋東昌地區(qū)。費用合理售后完善,十余年實體公司更值得信賴。
倒數(shù)第二位表示公民是男性還是女性(男性用單數(shù),女性用雙數(shù));
最后一位數(shù)字是一個隨機數(shù),又稱為校驗碼。 用來檢驗身份證的正確性。校檢碼可以是0~9的數(shù)字,有時也用x表示。
#includestdio.h
#include conio.h
#include stdlib.h
#include memory.h
#include string.h
#include time.h
#define AWARDER_NUM 10
typedef struct tag_award
{
char ID[20];
char name[20];
char telNo[20];
char address[50];
}AWARDER;
AWARDER * awarder = new AWARDER[AWARDER_NUM];
int first_award[1] = {-1};
int second_award[2] = {-1,-1};
int third_award[5] ={-1,-1,-1,-1,-1};
int awarder_num = 0;
void info_login()
{
if(awarder_num = AWARDER_NUM)
{
AWARDER * new_awarder = new AWARDER[awarder_num + AWARDER_NUM];
memcpy(new_awarder,awarder,awarder_num*sizeof(AWARDER));
delete awarder;
awarder = new_awarder;
}
printf("身份證號:");
scanf("%s",awarder[awarder_num].ID);
printf("姓名:");
scanf("%s",awarder[awarder_num].name);
printf("電話號碼:");
scanf("%s",awarder[awarder_num].telNo);
printf("家庭住址:");
scanf("%s",awarder[awarder_num].address);
awarder_num++;
}
void info_delete()
{
char name[20];
printf("輸入您要刪除的抽獎?wù)叩男彰?);
scanf("%s",name);
for(int i=0;iawarder_num;i++)
{
if (strcmp(awarder[i].name,name) == 0)
{
printf("您選擇刪除的抽獎?wù)叩男畔⑷缦拢篭n");
printf("身份證號:%s\n",awarder[i].ID);
printf("姓名:%s\n",awarder[i].name);
printf("電話號碼:%s\n",awarder[i].telNo);
printf("家庭住址:%s\n",awarder[i].address);
break;
}
}
if(i == awarder_num)
{
printf("沒有找到您輸入的抽獎?wù)撸n");
}
else
{
char c;
printf("您確定要刪除嗎?(Y//N)");
fflush(stdin);
scanf("%c",c);
if(c == 'Y' || c == 'y')
{
AWARDER * new_award = new AWARDER[awarder_num-1];
if(i = 0)
memcpy(new_award,awarder+1,sizeof(AWARDER) * (awarder_num - 1));
else if( i = awarder_num -1)
memcpy(new_award,awarder,sizeof(AWARDER) * (awarder_num - 1));
else
{
memcpy(new_award,awarder,sizeof(AWARDER) * i);
memcpy(new_award+i,awarder+i+1,sizeof(AWARDER) * (awarder_num - i - 1));
}
awarder_num--;
delete awarder;
awarder = new_award;
}
}
}
void info_modify()
{
char name[20];
printf("輸入您要修改的抽獎?wù)叩男彰?);
scanf("%s",name);
for(int i=0;iawarder_num;i++)
{
if (strcmp(awarder[i].name,name) == 0)
{
printf("您選擇的抽獎?wù)叩男畔⑷缦拢篭n");
printf("身份證號:%s\n",awarder[i].ID);
printf("姓名:%s\n",awarder[i].name);
printf("電話號碼:%s\n",awarder[i].telNo);
printf("家庭住址:%s\n",awarder[i].address);
break;
}
}
if(i == awarder_num)
{
printf("沒有找到您輸入的抽獎?wù)?!\n");
}
else
{
printf("請輸入該抽獎?wù)叩男滦畔ⅲ篭n");
printf("身份證號:");
scanf("%s",awarder[i].ID);
printf("姓名:");
scanf("%s",awarder[i].name);
printf("電話號碼:");
scanf("%s",awarder[i].telNo);
printf("家庭住址:");
scanf("%s",awarder[i].address);
}
}
bool check_over(int cur_award,int awarderNo)
{
if(awarderNo == 1)
{
if(cur_award == first_award[0])
return true;
}
else if(awarderNo = 3)
{
if(cur_award == first_award[0])
return true;
for(int i=0;iawarderNo-1;i++)
if(cur_award == second_award[i])
return true;
}
else if(awarderNo = 8)
{
if(cur_award == first_award[0])
return true;
for(int i=0;i2;i++)
if(cur_award == second_award[i])
return true;
for(i=0;iawarderNo-3;i++)
if(cur_award == third_award[i])
return true;
}
return false;
}
void award()
{
if(awarder_num 8)
{
printf("人數(shù)太少,請?zhí)砑幼銐虻娜嗽俪楠?!\n");
return;
}
srand((long)time(0));
char hit_id[20];
printf("\n開始抽第一等獎(1名),按任意鍵開始...\n");
getch();
while(!kbhit())
{
first_award[0] = rand() % awarder_num;
memcpy(hit_id,awarder[first_award[0]].ID,18);
printf("\r ");
printf("\r %s",hit_id);
}
printf("\n\n開始抽第二等獎(2名)");
for (int i=0;i2;i++)
{
printf("\n第%d個二等獎,按任意鍵開始...\n",i+1);
getch();
while(!kbhit())
{
second_award[i] = rand() % awarder_num;
while(check_over(second_award[i],1+i))
second_award[i] = rand() % awarder_num;
memcpy(hit_id,awarder[second_award[i]].ID,18);
printf("\r ");
printf("\r %s",hit_id);
}
}
printf("\n\n開始抽第三等獎(5名)");
for (i=0;i5;i++)
{
printf("\n第%d個三等獎,按任意鍵開始...\n",i+1);
getch();
while(!kbhit())
{
third_award[i] = rand() % awarder_num;
while(check_over(third_award[i],3+i))
third_award[i] = rand() % awarder_num;
memcpy(hit_id,awarder[third_award[i]].ID,20);
printf("\r ");
printf("\r %s",hit_id);
}
}
}
void info_show()
{
printf("一等獎獲得者:\n");
printf("\t身份證號:%s\n",awarder[first_award[0]].ID);
printf("\t姓名:%s\n",awarder[first_award[0]].name);
printf("\t電話號碼:%s\n",awarder[first_award[0]].telNo);
printf("\t家庭住址:%s\n",awarder[first_award[0]].address);
printf("二等獎獲得者:\n");
for (int i=0;i2;i++)
{
printf("第%d個二等獎獲得者:\n");
printf("\t身份證號:%s\n",awarder[second_award[i]].ID);
printf("\t姓名:%s\n",awarder[second_award[i]].name);
printf("\t電話號碼:%s\n",awarder[second_award[i]].telNo);
printf("\t家庭住址:%s\n",awarder[second_award[i]].address);
}
printf("三等獎獲得者:\n");
for (int i=0;i5;i++)
{
printf("第%d個三等獎獲得者:\n");
printf("\t身份證號:%s\n",awarder[third_award[i]].ID);
printf("\t姓名:%s\n",awarder[third_award[i]].name);
printf("\t電話號碼:%s\n",awarder[third_award[i]].telNo);
printf("\t家庭住址:%s\n",awarder[third_award[i]].address);
}
}
/*提示信息*/
bool raise()
{
printf("\n請輸入你需要的操作代號:\n");
printf("\t1.錄入:完成抽獎?wù)咝畔⒌妮斎?\n");
printf("\t2.刪除:完成抽獎?wù)咝畔⒌膭h除;\n");
printf("\t3.修改:允許對已經(jīng)錄入的數(shù)據(jù)重新進行編輯、修改;\n");
printf("\t4.抽獎:開始抽獎!\n");
printf("\t5.顯示:顯示所有中獎?wù)叩男畔?\n");
printf("\t6.退出。\n");
printf("==");
int operate;
fflush(stdin);
scanf("%d",operate);
switch(operate)
{
case 1:
info_login();
break;
case 2:
info_delete();
break;
case 3:
info_modify();
break;
case 4:
award();
break;
case 5:
info_show();
break;
case 6:
return false;
default:
break;
}
printf("\n操作完成。\n");
return true;
}
void main()
{
while(raise());
}
#include stdio.h
#include string.h
void main()
{
int len,year,month,day;
char str[30],str1[10];
printf("\n請輸入身份證號:\n");
gets(str);
len=strlen(str);
if(len==18)
{
sscanf(str, "%6c%4d%2d%2d", str1,year,month,day);
printf("出生日期:%d年%d月%d日\n",year,month,day);
}
else printf("輸入錯誤!\n");
}
身份證號碼中的第十七位通常是校驗碼,它是由前17位數(shù)字計算得出的,用于檢驗身份證號碼的有效性。要提取身份證號碼中的第十七位數(shù),可以使用C語言中的字符串處理函數(shù)strncpy和strlen。
下面是一個示例代碼:
在這個示例中,首先使用scanf函數(shù)讀入一個身份證號碼,并使用strlen函數(shù)計算它的長度。如果長度不為18,則認(rèn)為這個身份證號碼不合法,直接輸出錯誤信息并結(jié)束程序。
否則,可以通過字符串索引方式直接取出第十七位校驗碼,并將其輸出。注意,身份證號碼中的每一位都是一個字符,因此在定義身份證號碼的字符串時,需要預(yù)留一個額外的字符存儲字符串的結(jié)尾標(biāo)志\0,即定義為char id[19]。
需要注意的是,這只是提取身份證號碼中的第十七位校驗碼,如果要進行身份證號碼的完整校驗,需要進行復(fù)雜的運算,具體實現(xiàn)方式可能因地區(qū)而異。