博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2498 StuPId(我的水题之路——from back to front- -!)
阅读量:4069 次
发布时间:2019-05-25

本文共 2915 字,大约阅读时间需要 9 分钟。

StuPId
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 5830   Accepted: 3019

Description

Background 
At DUT, the Dreamland University of Technology, all students have personal id, numbers with six or seven digits. But they're not just any numbers. Only those that have a checksum with a zero as last digit can be valid ids. 
Problem 
Here's how to compute the checksum of an id number. Multiply the digits from back to front (!) with repeating factors 9, 3, 7. Then simply add the products. Example: 
id number :  1  3  9  0  2  7  2factors   :  9  7  3  9  7  3  9products  :  9 21 27  0 14 21 18
Here the checksum is 9+21+27+0+14+21+18 = 110. The last digit is zero, so the id is valid. Sometimes students have very bad handwriting and the teaching assistents have a hard time identifying the id’s. You're asked to help in special cases, where exactly one digit is unreadable. In that case, the missing digit can be computed (there's always exactly one correct digit, thanks to 9, 3 and 7 being relatively prime to 10). Note that the students always begin concentrated and thus the first digit will always be readable (and not zero).

Input

The first line contains the number of scenarios. Each scenario is a single line that contains an id number with one digit replaced by a question mark and with six or seven digits length.

Output

The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line containing the correct id number. Terminate the output for the scenario with a blank line.

Sample Input

413?02723?5678345?78314?592

Sample Output

Scenario #1:1390272Scenario #2:335678Scenario #3:345778Scenario #4:3146592

Hint

Huge input and output,scanf and printf are recommended.

Source

, Darmstadt, Germany
好吧,又是英文题,太恶心了!!一开始没有看懂,之后纠结了好久才发现是从后往前乘。
就是说有一个六或七位的数字,对于它从后向前每一位,一一对应的乘上{9,3,7}如例子(注意是从后向前),之后将各个乘积相加,保证最后之和可以被10整除,即是正确。现在给你这个数字,但是其中一个字母已经磨损了看不清,但它不会是第一个数字,现在请补全整个数字并且输出。
读懂题目之后,先想到的就是用字符数组存储,然后通过模拟,运算出已知数和
{9,3,7}的乘积之和,并且同时保存下缺少数字的位置和本应该乘以的数字,然后枚举0到9,看是否有符合要求的值,之后保存到原字符数组中,并输出。
代码(1AC):
#include 
#include
#include
char num[10];int mul[3] = {9, 3, 7};int main(void){ int ii, casenum; int sum, pos, need; int len, value; int i, j; scanf("%d", &casenum); for (ii = 1; ii <= casenum; ii++){ scanf("%s", num); len = strlen(num); sum = 0; for (i = len - 1, j = 0; i >= 0; i --, j++){ if (num[i] != '?'){ sum += mul[j % 3] * (num[i] - '0'); } else{ pos = i; need = mul[j % 3]; } } for (value = 0, i = 0; i <= 9; i++){ if ((i * need + sum) % 10 == 0){ value = i; break; } } num[pos] = value + '0'; printf("Scenario #%d:\n%s\n\n", ii, num); } return 0;}

转载地址:http://pooji.baihongyu.com/

你可能感兴趣的文章
大数据入门:Spark RDD基础概念
查看>>
大数据入门:SparkCore开发调优原则
查看>>
大数据入门:Java和Scala编程对比
查看>>
大数据入门:Scala函数式编程
查看>>
【数据结构周周练】002顺序表与链表
查看>>
C++报错:C4700:使用了非初始化的局部变量
查看>>
【数据结构周周练】003顺序栈与链栈
查看>>
C++类、结构体、函数、变量等命名规则详解
查看>>
C++ goto语句详解
查看>>
【数据结构周周练】008 二叉树的链式创建及测试
查看>>
《软件体系结构》 第九章 软件体系结构评估
查看>>
《软件体系结构》 第十章 软件产品线体系结构
查看>>
《软件过程管理》 第六章 软件过程的项目管理
查看>>
《软件过程管理》 第九章 软件过程的评估和改进
查看>>
《软件过程管理》 第八章 软件过程集成管理
查看>>
分治法 动态规划法 贪心法 回溯法 小结
查看>>
《软件体系结构》 练习题
查看>>
《数据库系统概论》 第一章 绪论
查看>>
《数据库系统概论》 第二章 关系数据库
查看>>
《数据库系统概论》 第三章 关系数据库标准语言SQL
查看>>