题目1197:奇偶校验
2014-01-16 19:30
218 查看
点击打开链接
/* 时间:2014.01.16.7.20 网址:http://ac.jobdu.com/problem.php?pid=1197 目的:题目1197:奇偶校验 */ #include <stdio.h> #include <string.h> main(int i,int j,int k,int asc) { char s[101]; int bin[8]; int cnt; while(gets(s)) { for(i = 0,cnt=0,memset(bin,0,sizeof(int)*8);s[i]; ++i,cnt=0,memset(bin,0,sizeof(int)*8)) { for(asc = s[i],j=0;asc != 0; j++) { bin[j] = asc%2; asc%2&&++cnt; asc>>=1;//移位 } cnt%2==0&&(bin[7]=1);//求最高位的奇校验 for(k=7;k>=0;printf("%d",bin[k]),k--);//倒着输出 printf("\n"); } } return 0; } /* 输出结果 ------------------------- 3 思路: 1.运用了短编程的思想 10110011 2.运用短除的方法,移位的思想 3a 3. 10110011 01100001 ------------------------- */
相关文章推荐
- struts2的<s:iterator>标签 遇到的问题:java.lang.ClassCastException:cannot be cast to java.lang.String
- 贪心(二)
- C# Socket编程
- ehcache memcache redis 三大缓存男高音
- 前缀表达式,中缀表达式,后缀表达式
- android 系统 makefile文件(Android.mk)组织结构
- Solr的学习使用之(四)建数据库(添加Core)、表(配置schema.xml)
- 你何时退伍呢?--让我帮你来计算
- wp8 点击ListBoxItem动画
- 寒假第三天--栈和队列--数据结构实验之栈三:后缀式求值
- DP for bombs
- CentOS,重启的常用命令
- 前缀&&中缀&&后缀表达式
- Ural 1437. Gasoline Station
- PL/SQL Developer如何连接64位的Oracle图解
- shell 返回返回值调用
- CodeSmith 使用教程(10): CodeTemplateInfo 对象
- Python语言学习笔记(一)
- javaSE-常用类-String
- CodeSmith 使用教程(9): Progress对象