您的位置:首页 > 其它

题目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
-------------------------
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: