UVa 11547: Automatic answer

Process
Not really any tricks to this problem. I used a long long to be on the safe side, but I don’t think it’s actually needed after some quick checks on my calculator. To get the digit in the tens column of a number, you can divide by 10 and use mod 10.
For example, to get the tens digit of 257:
257 / 10 = 25
25 % 10 = 5.

/*
 * Sai Cheemalapati
 * UVa 11547: Automatic answer
 *
 */

#include<cmath>
#include<cstdio>

using namespace std;

long long t, n;

int main() {
	scanf("%lld", &t);
	while(t--) {
		scanf("%lld", &n);
		n *= 567;
		n /= 9;
		n += 7492;
		n *= 235;
		n /= 47;
		n -= 498;
		n /= 10;
		printf("%d\n", (int) abs(n % 10));
	}
}
4
637
-120
9999
-9999
1
3
4
2
Advertisements

One thought on “UVa 11547: Automatic answer

  1. UVA Solution 11547 – Automatic Answer | Syed Ahmed Zaki

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s