Showing posts with label Volume CIV. Show all posts
Showing posts with label Volume CIV. Show all posts

Solution of 10487 - Closest Sums

Problem Description
source:https://uva.onlinejudge.org/external/104/10487.html

Given is a set of integers and then a sequence of queries. A query gives you a number and asks to find a sum of two distinct numbers from the set, which is closest to the query number.

Input 

Input contains multiple cases. 
       Each case starts with an integer n (1 < n ≤ 1000), which indicates, how many numbers are in the set of integer. Next n lines contain n numbers. Of course there is only one number in a single line. The next line contains a positive integer m giving the number of queries, 0 < m < 25. The next m lines contain an integer of the query, one per line. 
      Input is terminated by a case whose n = 0. Surely, this case needs no processing. 

image

Solution of 10469 - To Carry or not to Carry

Problem Description
source:https://uva.onlinejudge.org/external/104/10469.html

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