problemdetail.do?&method=showdetail&id=5131
来源:互联网 发布:仓库软件多少钱 编辑:程序博客网 时间:2024/06/01 22:56
toj5131:校验码
自己太菜了,写不出来,只能看大神的代码,然后理解意思,发现方法其实很简单,只是自己的思维不够严密,想不出来。这是我的第一篇博客,以后每天都把做过的题目发上来。希望能通过总结有所进步吧。不管是做咸鱼还是做菜鸟,希望自己能在这条路上走的久一点儿,就像crq说的,不要留遗憾。
加油!!!!!!!!!!!!!!!!
描述
校验码(jiào yàn mǎ)通常是一组数字的最后一位,由前面的数字通过某种运算得出,用以检验该组数字的正确性。常见的校验码有中华人民共和国居民身份证的最后一位、ISBN号码的最后一位、组织机构代码的最后一位、数据传输的正确性验证码等。
代码作为数据在向计算机或其它设备进行输入时,容易产生输入错误,为了减少输入错误,编码专家发明了各种校验检错方法,并依据这些方法设置了校验码。
算术极数法(Arithmetic method)
数字12345 每位对应极数5 4 3 2 1 所以校验码:1*5+2*4+3*3+4*2+5*1=35%11=2;
几何极数法(Geometric method)
数字12345 对应极数 16 8 4 2 1所以校验码:1*16+2*8+3*4+4*2+5*1=57%11=2;
质数法(Prime number method)
数字12345 对应极数11 7 5 3 2 所以校验码:1*11+2*7+3*5+4*3+5*2=62%11=7;
输入
输入数据有T组(T<100)
对于每组数据:
第一行输入一个数字(长度不超过10000)
第二行输入一段字符串,字符串有三种:第一种‘Arithmetic’,二种‘Geometric’,第三种‘Prime’
输出
对于每组数据输出一个校验码,当校验码为10时输出‘X’;
样例输入
3
12345
Arithmetic
12345
Geometric
12345
Prime
样例输出
2
2
7
//#include<stdio.h>#include<string.h>int d[110000];int main(){ int a[10005],b[10005],c[10005]; b[1]=1;a[1]=1; int i,j; for(i=2;i<=10000;i++) { a[i]=i%11; b[i]=b[i-1]*2%11; } memset(d,0,sizeof(d)); int k=1; for(i=2;;i++) { if(d[i]) continue; if(k>10000) break; c[k++]=i%11; for(j=i*2;j<=110000;j+=i) d[j]=1; } int t; char s[10005]; char ss[1000]; scanf("%d",&t); while(t--) { int sum=0; scanf("%s%s",s,ss); int l=strlen(s);//这里要注意,如果循环中直接用strlen的话会超时 if(strcmp(ss,"Arithmetic")==0) { for(i=0;i<l;i++) { sum+=(s[i]-'0')*a[l-i]; sum%=11; } } else if(strcmp(ss,"Geometric")==0) { for(i=0;i<l;i++) { sum+=(s[i]-'0')*b[l-i]; sum%=11; } } else { for(i=0;i<l;i++) { sum+=(s[i]-'0')*c[l-i]; sum%=11; } } if(sum==10) printf("X\n"); else printf("%d\n",sum); }}
- problemdetail.do?&method=showdetail&id=5131
- http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1072
- 什么是SoC(源引自 http://www.elenchina.com/bbs.do?method=view&id=1440&code=plate02)
- /ewcm008.do?flag=findVendor" method="post">
- request.getRequestDispatcher("/PlacardAction.do?method=toView").forward(request, response)
- http://www.renren.com/profile.do?id=220869953
- showdetail.php
- >> >>= do
- 【jsp】Fragment "/index.do?method=top" was not found at expected path
- http://xiaonei.com/getuser.do?id=228412237&t=6868435812
- http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1198&& I can do it!
- java如何获取jsp页面上传的文件路径 20 前台jsp: <form action="AA.do?method=yktAdd" method="post" > <input type='text'
- sizeof 笔记(转自http://student.csdn.net/space.php?uid=43658&do=blog&id=8677)
- What does Class.forname method do?
- Payment method do not display on frontend?
- What does Class.forname method do?
- 动词+名词=do something
- 微分流形与黎曼几何学习笔记(转自http://blog.sciencenet.cn/home.php?mod=space&uid=81613&do=blog&id=333317)
- android.os.Debug.waitForDebugger()使用需小心
- mysql索引
- hadoop 入门
- C++----声明、定义、const限定符
- bzoj1260
- problemdetail.do?&method=showdetail&id=5131
- Spring AOP 实现原理
- There's no Qt version assigned to this project for platform Win32
- 【剑指offer】把字符串转换成整数
- java----HashMap
- linux系统下守护进程的概念与实现简介
- 深入理解JavaScript系列(31):设计模式之代理模式
- Code Vs-problem-1204 寻找子串位置
- Linux命令基础25-group基本操作命令