九度OJ 1197:奇偶校验 简单的位操作习题
2012-02-15 09:19
253 查看
华科的这道考研上机题的大意是,给一个字符串,计算每个字符的二进制表示中的1的个数,如果有奇数个1,则奇偶位为0, 偶数个1,则奇偶位为1。
题目URL:http://ac.jobdu.com/problem.php?id=1197
我的AC代码:
题目URL:http://ac.jobdu.com/problem.php?id=1197
我的AC代码:
#include <iostream> #include <stdio.h> using namespace std; const int Max = 100 + 10; char d[Max]; int main() { int pos, ones; while(scanf("%s", d) != EOF) { pos = ones = 0; while(d[pos]) { ones = 0; for(int i(0); i<7; ++i) if(d[pos] & (1 << i)) ++ones; if(ones & 1) printf("0"); else printf("1"); for(int i(6); i>=0; --i) if(d[pos] & (1 << i)) printf("1"); else printf("0"); printf("\n"); ++pos; } } //system("pause"); return 0; }
相关文章推荐
- 你必须知道的简单的位操作技巧
- sql习题五--简单plsql
- python简单习题系列4
- 习题(简单IF~else)
- 关于字符串的一个简单的习题--输入一个数字,判断是几位数,打印每个数字及其重复的次数,依次打印个位到最高位
- 九度OJ - 1151 - 位操作练习
- 1197_奇偶校验
- C的一些简单习题(4)--连接两个字符串
- 题目1197:奇偶校验
- POJ 3046 Ant Counting 简单DP 挑战程序设计实战习题
- 九度OJ 1402 特殊的数 -- 位操作
- 简单算法习题--设置首字母大写
- 【简单习题】整数倒序
- 简单的位操作
- python 笔记 if语句的简单嵌套 《笨办法学Python》习题31 ——1.3
- 习题4-1象棋uva1589简单题解
- 九度oj-1127-简单密码
- 九度OJ 题目1127:简单密码
- [习题] FindControl 简单练习--GridView + CheckBox,点选多列数据(复选删除)#3 List或数组
- mooc中习题--简单运算器