UVa 10469 To Carry or not to Carry:异或

10469 - To Carry or not to Carry

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1410

6+9=15 seems okay. But how come 4+6=2? You see, Mofiz had worked hard throughout his digital logic course, but when he was asked to implement a 32 bit adder for the laboratory exam, he did some mistake in the design part. After tracing the design for half an hour, he found his flaw!! He was doing bitwise addition but his carry bit always had zero output. Thus,
 4 = 00000000 00000000 00000000 00000100
+6 = 00000000 00000000 00000000 00000110
----------------------------------------
 2 = 00000000 00000000 00000000 00000010

本文URL地址:http://www.bianceng.cn/Programming/sjjg/201410/45356.htm

Its a good thing that he finally found his mistake, but it was too late. Considering his effort throughout the course, the instructor gave him one more chance. Mofiz has to write an efficient program that would take2 unsigned 32 bit decimal numbers as input, and produce an unsigned 32 bit decimal number as the output adding in the same was as his circuit does.

Input

In each line of input there will be a pair of integer separated by a single space. Input ends at EOF.

Output

For each line of input, output one line -- the value after adding the two numbers in the "Mofiz way".

Sample Input

4 6
6 9

Sample Output

2
15

0+0=0

0+1=1

1+0=1

1+1=0

这不异或么。。

完整代码:

/*0.015s*/

#include<cstdio>  

int main()
{
    int a, b;
    while (~scanf("%d%d", &a, &b))
        printf("%d\n", a ^ b);
    return 0;
}

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索input
, 异或
, output
, The
BIT
why not carry on her、to be or not to be、whether or not、why or why not、cool mini or not,以便于您获取更多的相关知识。

时间: 2024-10-02 12:48:02

UVa 10469 To Carry or not to Carry:异或的相关文章

UVa 10035 Primary Arithmetic (陷阱较多~)

10035 - Primary Arithmetic Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=976 Children are taught to add multi-digit numbers from right-to-left one digit

WIN98SE硬盘主引导记录代码反汇编分析

硬盘引导记录MBR(Master Boot Record)是指硬盘之0面0道1扇区之内容,PC及其兼容机之ROM BIOS约定在上电及POST自检成功后,将其从硬盘读出,放置在内存0:7C00处,然后转去该地址执行.该段代码负责从代码尾部之4个分区表项中找出可以引导的项,读出其引导记录引导之.     MBR在相当长时间内都保持着1982年IBM设计IBM PC机时的代码原样,直到硬盘容量突破传统BIOS所能支持的最大容量8.4G之时,它才不得不加入新的INT13功能扩展代码,不过主要的功能还是

用javascript实现两个大数相乘

(function (){ var addLarge = function(n1,n2){ var carry = 0; var ret = ""; n1=n1.toString(); n2=n2.toString(); var len = Math.min(n1.length,n2.length); var sln1 = n1.substr(n1.length - len,n1.length ); var sln2 = n2.substr(n2.length - len,n2.len

LeetCode 2 Add Two Numbers

翻译: 给你两个表示两个非负数字的链表.数字以相反的顺序存储,其节点包含单个数字.将这两个数字相加并将其作为一个链表返回. 输入: (2 -> 4 -> 3) + (5 -> 6 -> 4) 输出: 7 -> 0 -> 8 原题: You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of

c-C++ MFC有进程没有界面

问题描述 C++ MFC有进程没有界面 LRESULT CALLBACK WinSunPrnc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrcvInstance, LPSTR IpCmdLine, int nCmdShow ) { WNDCLASS wndcls; wndcls.cbClsExtra = 0;//类的附加字节数

编程 语言 c语言-C语言编程 加减乘除。。。

问题描述 C语言编程 加减乘除... 有这样一道题,现在由于精度问题,数字加减会有误差,现要编辑一个程序,使得输入数字无误差,并给定长度在规定字符串数组(30),求加法(包含小数 解决方案 shell数值计算(加减乘除) 解决方案二: 我是来围观的我是来围观的我是来围观的 解决方案三: #include #include #include using namespace std; void main() { char ch[ 30 ]; memset( ch, '?', 30 ); cin>>

C语言综合实验2—长整数运算

1.实验题目:长整型数运算,C中的long int所能表示的数据范围有限,现要求编程完成超过long int所能表示的数据范围以上的十进制正的长整数的加法和乘法运算. 2.实验提示:两个参与运算的长整数可用char a[256], b[256]表示,整个程序中要求完成以下几个函数的编写:1) int readlongint(char * x); 此函数用于读入一个正的长整数到x中,函数返回长整数的实际长度:要求输入时检查所读入的字符串是否是合法的长整数,如不是提示用户直到输入合法的长整数为止:2

[LeetCode]--415. Add Strings

Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. Note: The length of both num1 and num2 is < 5100. Both num1 and num2 contains only digits 0-9. Both num1 and num2 does not contain any leading zero.

C++实现大数乘法算法代码_C 语言

C++实现大数乘法算法代码 复制代码 代码如下: //大数乘法算法 #include<iostream> #include<string> #include<cstring> using namespace std; int main() {     string num1,num2;     cin >> num1 >> num2;     //cout << num1.size() << " " &