#includeusing namespace std;int main(){char letter, b[11];int x, S=0, i;cin >> letter;for (i=2; i<=10; i++)cin >> b[i];if (letter >= 'A' && letter <= 'H')x = (int)letter - 55;if (letter >= 'J' && letter <= 'N')x = (int)letter - 56;if (letter >= 'P' && letter <= 'Z')x = (int)letter - 57;if (letter == 'I')x = (int)letter - 39;if (letter == 'O')x = (int)letter - 44;b[0] = x/10;b[1] = x%10;for (i=2; i<=10; i++){S += b[i]*(11-i);S = S + b[0] + b[1]*9 + b[10];}if (S%10 == 0)cout << "real" << endl;elsecout << "fake" << endl;return 0;}output都是fake😵💫
這......錯的地方有點多啊
1. if (letter >= 'P' && letter <= 'Z')
WXY錯了
2. 你的b是字元陣列,但是你把它當數字了,要先減48才行
3.for (i=2; i<=10; i++)
i<=9
4. S += b[i]*(11-i)
是10-i
5. S = S + b[0] + b[1]*9 + b[10]
只要執行一次就好了,所以移到for迴圈外