**UVA Problem 12614 ( Earn For Future ) Solution:**

Click here to go to this problem in uva Online Judge.

**Solving Technique:**

Like many other programming problem this tries to tangle us with its complex language and useless data to through us off the right path. I have provided three working solutions with same logic but with some optimizations.

**This program simply requires us to find the max number among given inputs.**

At first glance it may seem like we need to bitwise * &* ( and ) all given value for the result. But trying that doesn’t yield the right answer.

**If you need to know what this problem is about:**

The problem says bitwise operation will be performed on card numbers. But we do not need to perform bitwise operations. It is not our concern. But the problem also says that he have picked N cards. Now he needs to choose more cards to maximize his gain. The problem say, ” Please tell him the **maximum amount** he can win from these set of cards”. This means we obviously need to pick the biggest number because we want to maximize the amount ( performing bitwise ** & **( and ) with the biggest number instead of a smaller gives us a bigger number ).

** Important: **Be sure to add or print a new line after each output. The outputs should match exactly because sometimes even a space character causes the answer to be marked as wrong answer.

**Code Explanation:**

The first line of input is the number of test cases (* n* ). The next line of input the number of inputs (I used

*in my code) to come. Following m lines inputs.*

**m**Here we do not need an array to store the variable. We can just calculate as the values are being given. For every test case I use the first card number as the max number, then I compare other inputs against it.

**Input:**

6 2 0 1 2 3 5 3 0 1 2 4 0 0 9 1 5 0 99 1 9 5 6 8 0 7 5 8 5

**Output:**

Case 1: 1 Case 2: 5 Case 3: 2 Case 4: 9 Case 5: 99 Case 6: 8

### Using some assumption**:**

/* * @author Quickgrid ( Asif Ahmed ) * @link https://quickgrid.wordpress.com * Problem UVA 12614 ( Earn For Future ) */ #include<stdio.h> int main(){ register unsigned n, i; /* * Since we are told we won't get any negative numbers */ unsigned m, a, max, c = 1; scanf("%u", &n); while (n--){ /* * Assuming m is at least 1, so i scan the first one as max */ scanf("%u%u", &m, &max); /* * Already one input taken, so decrease counter */ m -= 1; while (m--){ scanf("%u", &a); if (a > max) max = a; } printf("Case %u: %u\n", c++, max); } return 0; }

**Another one with custom scanning and some bit-wise tricks:**

/* * Author: Quickgrid ( Asif Ahmed ) * Site: https://quickgrid.wordpress.com * Problem: UVA 12614 ( Earn For Future ) */ #include<stdio.h> void Rfastscan(register unsigned &x){ register int c; x = 0; c = getchar(); for(;(c > 47 && c < 58); c = getchar()) x = (x << 1) + (x << 3) + c - 48; } void fastscan(int &x){ unsigned neg = 0; register int c; x = 0; c = getchar(); if(c == '-'){ neg = 1; c = getchar(); } for(;(c > 47 && c < 58); c = getchar()) x = (x<<1) + (x<<3) +c -48; if(neg) x = ~x+1; /* 2's complement */ } int main(){ register unsigned n, m, i, c = 1; int a, max; Rfastscan(n); while(n--){ Rfastscan(m); fastscan(max); for(i=1; i<m; ++i){ fastscan(a); if(a > max) max = a; } printf("Case %u: %u\n", c++, max); } return 0; }