#41204:


yp11351100@yphs.tp.edu.tw (701裡最聰明的辣個人)

學校 : 臺北市私立延平高級中學
編號 : 276234
來源 : [203.72.178.1]
最後登入時間 :
2024-09-12 17:29:03
a020. 身分證檢驗 | From: [203.72.178.1] | 發表日期 : 2024-07-11 13:24

又臭又長的答案
#include<stdio.h> #include<string.h> int main(){ char identity[11]; int check[11]; int i; int sum,temp; while(scanf("%s",&identity)!=EOF) { if(identity[0]=='A') { check[0]=1; check[1]=0; } if(identity[0]=='B') { check[0]=1; check[1]=1; } if(identity[0]=='C') { check[0]=1; check[1]=2; } if(identity[0]=='D') { check[0]=1; check[1]=3; } if(identity[0]=='E') { check[0]=1; check[1]=4; } if(identity[0]=='F') { check[0]=1; check[1]=5; } if(identity[0]=='G') { check[0]=1; check[1]=6; } if(identity[0]=='H') { check[0]=1; check[1]=7; } if(identity[0]=='I') { check[0]=3; check[1]=4; } if(identity[0]=='J') { check[0]=1; check[1]=8; } if(identity[0]=='K') { check[0]=1; check[1]=9; } if(identity[0]=='L') { check[0]=2; check[1]=0; } if(identity[0]=='M') { check[0]=2; check[1]=1; } if(identity[0]=='N') { check[0]=2; check[1]=2; } if(identity[0]=='O') { check[0]=3; check[1]=5; } if(identity[0]=='P') { check[0]=2; check[1]=3; } if(identity[0]=='Q') { check[0]=2; check[1]=4; } if(identity[0]=='R') { check[0]=2; check[1]=5; } if(identity[0]=='S') { check[0]=2; check[1]=6; } if(identity[0]=='T') { check[0]=2; check[1]=7; } if(identity[0]=='U') { check[0]=2; check[1]=8; } if(identity[0]=='V') { check[0]=2; check[1]=9; } if(identity[0]=='W') { check[0]=3; check[1]=2; } if(identity[0]=='X') { check[0]=3; check[1]=0; } if(identity[0]=='Y') { check[0]=3; check[1]=1; } if(identity[0]=='Z') { check[0]=3; check[1]=3; } for(i=1;i<10;i++) { if(identity[i]=='0') check[i+1]=0; if(identity[i]=='1') check[i+1]=1; if(identity[i]=='2') check[i+1]=2; if(identity[i]=='3') check[i+1]=3; if(identity[i]=='4') check[i+1]=4; if(identity[i]=='5') check[i+1]=5; if(identity[i]=='6') check[i+1]=6; if(identity[i]=='7') check[i+1]=7; if(identity[i]=='8') check[i+1]=8; if(identity[i]=='9') check[i+1]=9; } sum=0; sum=check[0]+check[10]; for(i=1;i<10;i++) { temp=check[i]*(10-i); sum+=temp; } if(sum%10==0) printf("real\n"); else printf("fake\n"); } return 0; }
 
#41225: Re: 答案


yp11251120@yphs.tp.edu.tw (808-43杜波波)

學校 : 臺北市私立延平高級中學
編號 : 237257
來源 : [203.72.178.1]
最後登入時間 :
2024-11-06 17:51:13
a020. 身分證檢驗 | From: [203.72.178.1] | 發表日期 : 2024-07-12 14:17

又臭又長的答案
#include #include int main(){ char identity[11]; int check[11]; int i; int sum,temp; while(scanf("%s",&identity)!=EOF) { if(identity[0]=='A') { check[0]=1; check[1]=0; } if(identity[0]=='B') { check[0]=1; check[1]=1; } if(identity[0]=='C') { check[0]=1; check[1]=2; } if(identity[0]=='D') { check[0]=1; check[1]=3; } if(identity[0]=='E') { check[0]=1; check[1]=4; } if(identity[0]=='F') { check[0]=1; check[1]=5; } if(identity[0]=='G') { check[0]=1; check[1]=6; } if(identity[0]=='H') { check[0]=1; check[1]=7; } if(identity[0]=='I') { check[0]=3; check[1]=4; } if(identity[0]=='J') { check[0]=1; check[1]=8; } if(identity[0]=='K') { check[0]=1; check[1]=9; } if(identity[0]=='L') { check[0]=2; check[1]=0; } if(identity[0]=='M') { check[0]=2; check[1]=1; } if(identity[0]=='N') { check[0]=2; check[1]=2; } if(identity[0]=='O') { check[0]=3; check[1]=5; } if(identity[0]=='P') { check[0]=2; check[1]=3; } if(identity[0]=='Q') { check[0]=2; check[1]=4; } if(identity[0]=='R') { check[0]=2; check[1]=5; } if(identity[0]=='S') { check[0]=2; check[1]=6; } if(identity[0]=='T') { check[0]=2; check[1]=7; } if(identity[0]=='U') { check[0]=2; check[1]=8; } if(identity[0]=='V') { check[0]=2; check[1]=9; } if(identity[0]=='W') { check[0]=3; check[1]=2; } if(identity[0]=='X') { check[0]=3; check[1]=0; } if(identity[0]=='Y') { check[0]=3; check[1]=1; } if(identity[0]=='Z') { check[0]=3; check[1]=3; } for(i=1;i<10;i++) { if(identity[i]=='0') check[i+1]=0; if(identity[i]=='1') check[i+1]=1; if(identity[i]=='2') check[i+1]=2; if(identity[i]=='3') check[i+1]=3; if(identity[i]=='4') check[i+1]=4; if(identity[i]=='5') check[i+1]=5; if(identity[i]=='6') check[i+1]=6; if(identity[i]=='7') check[i+1]=7; if(identity[i]=='8') check[i+1]=8; if(identity[i]=='9') check[i+1]=9; } sum=0; sum=check[0]+check[10]; for(i=1;i<10;i++) { temp=check[i]*(10-i); sum+=temp; } if(sum%10==0) printf("real\n"); else printf("fake\n"); } return 0; }

學弟可以先用陣列存好再做喔

給個示範

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int y[26]={10,11,12,13,14,15,16,17,34,18,19,20,21,22,35,23,24,25,26,27,28,29,32,30,31,33};
    int sum=0;
    for(int i=0; i<s.length(); i++)
    {
    	if(i==0) sum+=y[int(char(s[0]))-65]/10+(y[int(char(s[0]))-65]%10)*9;
    	else  sum+=(9-i)*(s[i]-'0');
	}
	sum+=s[9]-'0';
	if(sum%10==0) cout<<"real"<<endl;
	else cout<<"fake"<<endl;
}
 
ZeroJudge Forum