C - 获取出生日期(so easy)

  1. #include <cstdio>
  2. int main() {
  3. int n;
  4. int a, b, c, d, e;
  5. scanf_s("%d", &n);
  6. while (n--) {
  7. scanf_s("%6d%4d%2d%2d%3d", &a, &b, &c, &d, &e); //最后一个可能是字母,所以不读入处理
  8. int a1 = getchar(); //用两个getchar跳过
  9. int a2 = getchar();
  10. printf("%04d-%02d-%02d\n", b, c, d);
  11. }
  12. return 0;
  13. }
  14. /*
  15. 3
  16. 41010619941117865X
  17. 410104198202095479
  18. 410122197911218097
  19. */

G - 检验身份证(数组yyds!)

  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. int wei[17] = { 7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,24 };
  5. int rela[11] = { 1,0,10,9,8,7,6,5,4,3,2, };
  6. bool func(string s) { //1:passed 0:not passed
  7. int a[18];
  8. /*字符串处理为实数数组*/
  9. for (int i = 0; i < 17; i++) {
  10. if (!isdigit(s[i])) {
  11. cout << s << endl;
  12. return 0;
  13. }
  14. a[i] = s[i] - '0';
  15. }
  16. if (s[17] == 'x') a[17] = 10;
  17. else a[17] = s[17] - '0';
  18. /*权运算得验证码*/
  19. int Z = 0;
  20. for (int i = 0; i < 17; i++) {
  21. Z += a[i] * wei[i];
  22. Z = Z % 11;
  23. }
  24. /*验证*/
  25. if (a[17] == rela[Z]) return 1;
  26. else {
  27. cout << s << endl;
  28. return 0;
  29. }
  30. }
  31. int main() {
  32. int n, count = 0;
  33. string s;
  34. cin >> n;
  35. for (int i = 1; i <= n; i++) {
  36. cin >> s;
  37. if (func(s)) count++;
  38. if (count == n) cout << "All passed" << endl;
  39. }
  40. return 0;
  41. }