题目1197:奇偶校验

2014-11-24 08:06:34 · 作者: · 浏览: 0

点击打开链接

/*
      时间:2014.01.16.7.20 
     网址:http://ac.jobdu.com/problem.php pid=1197 
	目的:题目1197:奇偶校验 
*/
#include 
  
   
#include 
   
     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 ------------------------- */