UVA Problem 12854 – Automated Checking Machine Solution

UVA Problem 12854 – Automated Checking Machine Solution:


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

Solving Technique:

For This problem I tried many times but best I could get was rank 116 and run time 0.009 s ( 9 ms ). This is really bad for a very simple code.

The logic is simple we are given two strings ( or, 10 integers ) . If the character in the same index / position of the two strings are different we print Y. Otherwise if the characters are same we print N.

Since I know that there will 5 and 5 total of 10 characters each time. So I used integer to take input.

Now I used XOR between to integers because applying XOR to two integers if they are equal then we get 0. Otherwise we get a 1. XOR table,

a b a^b
0 0  0
0 1  1
1 0  1
1 1  0

So that is what I need if they are same i get 0 and else I get 1. Using this logic I check all 10 values. Then use ternary operation to print Y or, N.

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


Input:

1 1 1 1 1
0 0 0 0 0
1 1 0 1 0
0 0 1 0 1
1 0 0 1 0
1 0 1 1 0

Output:

Y
Y
N

Code:

/*
 * @author Quickgrid ( Asif Ahmed )
 * @link https://quickgrid.wordpress.com
 * Problem: UVA 12854 - Automated Checking Machine
 */

#include<stdio.h>
int main(){
    register unsigned int a,b,c,d,e,f,g,h,i,j;
	while (scanf("%u%u%u%u%u%u%u%u%u%u", &a, &b, &c, &d, &e, &f, &g, &h, &i, &j) == 10){
        (a ^ f && b ^ g && c ^ h && d ^ i && e ^ j) ? printf("Y\n"): printf("N\n");
	}
	return 0;
}
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s