题目描述

Parity is an important concept in data transmission.  Because the process is not error proof, parity is used to provide a check on whether or not data has been corrupted in transmission. 
If even parity is being used, each byte will have an even number of 1 characters.  If odd parity is being used, each byte will have an odd number of 1 characters. 
In this problem, we are looking for a single bit that has been corrupted.  To help you find it, the last byte is not part of the data being transmitted, but is a parity byte.  Each bit of the parity byte will be used to make the corresponding bits in the data bytes odd or even depending on the parity being used.  

输入

The first line of input is a single integer, N (3 <= N <= 10), the number of bytes of data to follow.  The next N lines each contain a single byte of data consisting of 8 characters separated by spaces.  Each character will be either 1 or 0.  
There will be one further line of 8 characters (again 1 or 0) which will be the parity byte.In  the  parity  byte,  each  bit  is  a  parity  bit  for  the  corresponding  bits  in  the preceding N lines, using the same parity as is used by the data bytes.  The parity byte itself may not show the same parity as the data bytes. 

输出

Output 3 lines of information about the data in the input. 
Line 1:  Either the word Even or the word Odd to describe the parity being used by the bytes which are not broken. 
Line 2:  Byte <number> is broken 
Line 3:  Bit <number> is broken 
<number> is the number of the appropriate byte or bit, where the first of each is number 1. 

样例输入

3
1 0 1 0 1 1 1 0
1 1 0 1 1 1 0 0
1 0 1 1 1 0 0 0
0 0 1 1 1 1 0 1

样例输出

Odd
Byte 3 is broken
Bit 5 is broken

提示

Bytes 1 and 2 have an odd number of 1s but byte 3 has an even number.  So odd parity is being used but byte 3 is broken. 
The  parity  byte gives  all  columns  of  bits an odd  number  of  1s except for 5 where they are even, so bit 5 is broken.  Bit 5 of byte 3 is corrupt.

【题解】:

很难得遇到一道组成原理为背景的题目了,深感欣慰,觉得这个题目有必要记录一下。

首先判断:奇数还是偶数判别法

其次判断那一个字节出现了问题。

最后判别哪一位上出现问题。

 #include<bits/stdc++.h>
using namespace std;
const int N = ;
int a[N][N];
int s[N],n;
int row[N],col[N];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) for(int j=;j<=;j++)
scanf("%d",&a[i][j]),row[i]+=a[i][j],col[j] += a[i][j] ; for(int i=;i<=;i++)
scanf("%d",&s[i]),col[i]+=s[i]; int OE = , Odd = ,Even = ;
for(int i=;i<=n;i++){
if( row[i]& ) Odd ++ ;
else Even ++ ;
}
if( Odd == n- ) OE = ;
if( Even == n- ) OE = ;
//Ans 1
if( OE& ){
puts("Odd");
}else{
puts("Even");
} //Ans 2
for(int i=;i<=n;i++){
if( (OE & ) && (row[i]%==) ){
printf("Byte %d is broken\n",i);break;
}else if( (OE%==) && (row[i]&) ){
printf("Byte %d is broken\n",i);break;
}
} //Ans 3
for(int j=;j<=;j++){
if( (OE & ) && (col[j]%==) ){
printf("Bit %d is broken\n",j);break;
}else if( (OE%==) && (col[j]&) ){
printf("Bit %d is broken\n",j);break;
}
} return ;
}

【组成原理】BYTE ME!的更多相关文章

  1. weblogic漏洞总结 复现(未完)

    复现方式 Docker复现 WEBlogic爆出了很多漏洞 先了解一下现在主流的版本 Weblogic 10.3.6.0 Weblogic 12.1.3.0 Weblogic 12.2.1.1 Web ...

  2. 计算机存储负数以及int转byte时-128的出现

    我们看下面这段代码 输出的结果的是128,这个没什么疑问 但是当我们不改变数值仅仅加了一个强制转换后 这时我们会发现结果会变成负的128.这时候我们就要怀疑了,为什么会出现这样的结果呢? 对于这个问题 ...

  3. Java中基本数据类型byte,short,char,int,long,float,double 取值范围

    部分内容转自:java 彻底理解 byte char short int float long double 首先说byte: 这段是摘自jdk中 Byte.java中的源代码: /** * A co ...

  4. java 彻底理解 byte char short int float long double

    遇到过很多关于 数值类型范围的问题了,在这做一个总结,我们可以从多方面理解不同数值类型的所能表示的数值范围 在这里我们只谈论 java中的数值类型 首先说byte: 这段是摘自jdk中 Byte.ja ...

  5. C#基础蛋疼到爆的Byte类型表数范围之网兜毛衣见解……

    事实上写这篇对Byte类型表数范围的文章,真的是蛋疼+蛋疼+蛋疼,每每看到Byte表数范围这一块.都对-128如此的陌生与迷茫.操蛋的Byte,操蛋的人生-- 熊孩子出场:Byte 恶作剧结果:表数范 ...

  6. 详解计算机中的Byte、bit、字、字长、字节

    最近突然有同事问我,关于计算机中的计量单位大B和小b的区别,以及KB到GB之间的换算问题,我当时觉得这问题简单,大B是 byte,小b是bit,但是想到他俩之间的换算时,一时有些想不起来具体是1Byt ...

  7. go语言:多个[]byte数组合并成一个[]byte

    场景:在开发中,要将多个[]byte数组合并成一个[]byte,初步实现思路如下: 1.获取多个[]byte长度 2.构造一个二维码数组 3.循环将[]byte拷贝到二维数组中 package gst ...

  8. Android-Drawable、Bitmap、byte[]、资源文件相互转换

    我们在Android的开发中,经常可以遇到图片的处理,当中,有很多是 Bitmap.Drawable.byte[]和资源文件它们直接相互转换. 今天就此总结一下: 1.资源文件转为Drawable 2 ...

  9. byte[] 转成图片方法

    /// <summary> /// ImageData 的摘要说明 /// </summary> public class ImageData : IHttpHandler { ...

随机推荐

  1. Mac 卸载Python3.6

    Mac 自带的 Python 已经能够满足我们的需要了,因此很多同学在安装完 Python 之后,又想要将其删除,或者称之为卸载. 对于删除 Python,我们首先要知道其具体都安装了什么,实际上,在 ...

  2. 20190710记录:去掉中转图,直接以1280*1024进行反坐标计算,填补pbFinal。

    1.记录:去掉中转图,直接以1280*1024进行反坐标计算.pbFinal=1280*1024. // Imagejoint.cpp : 定义控制台应用程序的入口点. // #include &qu ...

  3. 编程语言中的字面量在Objective-C中的举例

    关于计算机编程语言中的字面量的介绍可参考:http://baike.baidu.com/view/1208327.htm?fr=aladdin. 下面就介绍Objective-C中的各种常用字面量: ...

  4. python 时间对比

    import datetimed1 = datetime.datetime.strptime('2015-03-05  17:41:20', '%Y-%m-%d %H:%M:%S')d2 = date ...

  5. Python操作memecache

    memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载,故常用来做数据库缓存.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态 ...

  6. JAVA 基础编程练习题36 【程序 36 移动位置】

    36 [程序 36 移动位置] 题目:有 n 个整数,使其前面各数顺序向后移 m 个位置,最后 m 个数变成最前面的 m 个数 package cskaoyan; public class cskao ...

  7. Reveal v4(8796) 使用

    文件下载地址   http://xclient.info/s/reveal.html dmg安装成功后, pod install  植入项目. pod 'Reveal-SDK', '~> 4', ...

  8. 反向代理远端 单台tomcat 使用ip+端口

    .环境 nginx 10.1.1.161 公网:123.58.251.166 tomcat 10.1.1.103 .tomcat 配置 [root@host---- ~]# netstat -tnlp ...

  9. LODOP设置纸张无效问题

    有的打印机不支持自定义纸张,或不支持当前设置的纸张尺寸,会造成纸张尺寸和代码里设置的尺寸不一致的情况.现象:1.代码一样,纸张语句设置正确,有的打印机纸张正常,有的打印机不正常.2.代码一样,纸张语句 ...

  10. HOSTS大法解决Github Clone太慢

    经常要clone github中的一些项目,无奈如果不爬梯子的话速度实在是龟速,经常1k/s,于是搜了下解决方法,改HOSTS大法. Windows下在C:/Windows/system32/driv ...