POJ-2190-ISBN解题思路

POJ-2190-ISBN解题思路

来源: | 浏览: 1834 | 评论: 3发表时间: 2015-06-06 20:56:24

Farmer John's cows enjoy reading books, and FJ has discovered that his cows produce more milk when they read books of a somewhat intellectual nature. He decides to update the barn library to replace all of the cheap romance novels with textbooks on algorithms and mathematics. Unfortunately, a shipment of these new books has fallen in the mud and their ISBN numbers are now hard to read.



Description

An ISBN (International Standard Book Number) is a ten digit code that uniquely identifies a book. The first nine digits represent the book and the last digit is used to make sure the ISBN is correct. To verify that an ISBN number is correct, you calculate a sum that is 10 times the first digit plus 9 times the second digit plus 8 times the third digit ... all the way until you add 1 times the last digit. If the final number leaves no remainder when divided by 11, the code is a valid ISBN. For example 0201103311 is a valid ISBN, since 10*0 + 9*2 + 8*0 + 7*1 + 6*1 + 5*0 + 4*3 + 3*3 + 2*1 + 1*1 = 55. Each of the first nine digits can take a value between 0 and 9. Sometimes it is necessary to make the last digit equal to ten; this is done by writing the last digit as X. For example, 156881111X is a valid ISBN number. Your task is to fill in the missing digit from a given ISBN number where the missing digit is represented as '?'.


Input

* Line 1: A single line with a ten digit ISBN number that contains '?' in a single position


Output

* Line 1: The missing digit (0..9 or X). Output -1 if there is no acceptable digit for the position marked '?' that gives a valid ISBN.


Sample Input
Sample Output
解题思路

循环相乘以权值然后判断即可,需要注意的是'X'只能出现在第9个位置(从0数起的话)。


AC代码


相关文章
  • 声明: 评论属于其发表者所有,不代表本站的观点和立场.
  • 火锅桌椅回复该留言时间: 2015-06-16 17:18:06

    看不明白,有没中文版的。

  • 中山摄影回复该留言时间: 2015-07-02 13:44:29

    内容不错

  • af论坛回复该留言时间: 2015-07-20 15:12:02

    技术型博客果断收藏。

已有 3 位网友发表了一针见血的评论,你还等什么?
  • 昵称: *
  • 邮箱:
  • 网址:
  • 记住我的信息
  • Color
  • Red
  • Blue
  • Code
  • bash
  • cpp
  • css
  • java
  • js
  • perl
  • php
  • python
  • ruby
  • sql
  • xml








最新评论