EaglePB2's Competitive Programming Writeups
  • Home Page
  • Why Python?
  • Why 10^9 + 7?
  • General Formatting Title
  • šŸ‡²šŸ‡¾CodeNection
    • 2021
      • Closed Cateogry
        • Attend Talks
        • Distant Relatives
        • Concert
        • Mamak
        • Fair Contest
      • Open Preliminary Round
        • f(Aibohphobia)^-1
        • Did they cheat?
        • Semester Breaks
      • Open Final Round
        • Ways 1
        • Circular Campus
        • A joke
        • 🄰Last year when life was better
        • Thank You Pizza
    • 2023
      • Test Round
        • Codey and Alphabetical Scoring
        • Codey and Binary Guesser
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Hide-and-Seek
        • Codey and Math
        • Codey and Textbooks
        • Codey and Money
        • Codey and Team Selection
        • Codey and Painted Tree
        • Codey and Number Grid
        • Codey and Crimes
      • Final Round
        • Codey and CodeNection 2
        • Codey and Connection
        • Codey and Schedule
        • Codey and School Supplies
        • Codey and Zombies
        • Codey and Sightseeing
        • Codey and Apples
        • Codey and Facto
        • Codey and Zoey
    • 2024
      • Test Round
        • Codey and Sunday
        • Codey and Takoyaki
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Pebbles
        • Codey and Spam
        • Codey and Coins
        • Codey and Rectangles
        • Codey and Manuscript
        • Codey and Recipes
        • Codey and Toy Kingdom
        • Codey and Peaks
      • Final Round
        • Codey and Exit
        • Codey and Gardening
        • Codey and Symbol
        • Codey and Rectangles 2
        • Codey and Jutsu
        • Codey and Toy Kingdom 2
        • Codey and Speeches
  • ABaKoDa
    • 2023
      • Round 1
        • Problem Letters
        • Problem Statistics
        • Rankings Order
        • Rankings Search
      • Round 2
        • Abakoda Letters
        • Borrowed Words
        • Kensorship
        • Duel Languages
  • Meta Coding Competitions
    • 2011
      • Qualification Round
        • Double Squares
        • Peg Game
        • Studious Student
      • Round 1A
        • Diversity Number
        • Turn on the Lights
        • Wine Tasting
      • Round 1B
        • Chess 2
        • Diminishing Circle
        • Slot Machine Hacker
      • Round 1C
        • N-Factorful
        • Polynomial Factoring
        • Risky Slide
      • Round 2
        • Bonus Assignments
        • Scott's New Trick
        • Studious Student II
      • Final Round
        • Alien Game
        • Party Time
        • Safest Place
  • EaglePB2's Special
    • Hong Kong Identity card
    • Cycle Prefix Averages
    • Word Squares
Powered by GitBook
On this page
  • Question
  • Input Format
  • Constraints
  • Output Format
  • Sample Inputs:
  1. EaglePB2's Special

Hong Kong Identity card

Difficulty: Basic

Question

The Hong Kong Identity Card consists of 1 English letter and 6 numeric digits. A check digit, which could be 0 to 9 or A, is appended in brackets. It is calculated as follows:

  • For letters, A is converted to value 1, B to value 2, and so on.

  • For every HKID number LD1D2D3D4D5D6LD_1D_2D_3D_4D_5D_6LD1​D2​D3​D4​D5​D6​, the sum is S=8L+7D1+6D2+5D3+4D4+3D5+2D6S= 8L + 7D_1 + 6D_2 + 5D_3 +4D_4 + 3D_5 +2D_6S=8L+7D1​+6D2​+5D3​+4D4​+3D5​+2D6​.

  • The check digit c shall be the smallest non-negative integer such that (s+c)%11=0(s + c)\%11=0(s+c)%11=0. If c is 10, A is used instead.

Write a program to determine if the Identity Card is valid.

Input Format

A line which consists of the format LD1D2D3D4D5D6(c)LD_1D_2D_3D_4D_5D_6(c)LD1​D2​D3​D4​D5​D6​(c).

Constraints

A≤L≤ZA \le L \le ZA≤L≤Z
0≤D1,D2,...D6≤90 \le D_1,D_2,...D_6\le90≤D1​,D2​,...D6​≤9
0≤c≤9,orĀ c=A0 \le c \le 9, or\ c=A0≤c≤9,orĀ c=A

Output Format

Output 'YES' if the card is valid, otherwise, output 'NO'.

Sample Inputs:

Input

A123456(3)

Output

True

Input

C876300(0)

Output

false
Solution — Trivial

just follow the steps, and make it as a warmup. The harder part is actually how to split the characters instead.

Here's the solution:

user_in = list(input())
user_in[0] = ord(user_in[0].upper()) - ord('A') + 1
if user_in[8] == 'A':
    user_in[8] = 10

big_num = 8
sum = 0

for ins in range(7):
    sum += big_num * int(user_in[ins])
    big_num -= 1

if((sum + int(user_in[8])) % 11 == 0):
    print("yes")
else:
    print("no")
PreviousSafest PlaceNextCycle Prefix Averages

Last updated 2 months ago