Showing posts with label fen. Show all posts
Showing posts with label fen. Show all posts

Saturday, September 3, 2016

UVa 12414 Calculating Yuan Fen

UVa 12414 Calculating Yuan Fen



Method: Simulate it, nothing special. But dont handle with strings. TLE for sure then.

#include <stdio.h>

int y(char *s, int st) {
int val[100], stor[100], v, i, j, k=0;
for (i=0 ; s[i] ; i++) {
v = s[i]+st-A;
for (j=0 ; v ; j++, v/=10) {
stor[j] = v%10;
}
for (--j ; j>=0 ; j--, k++) {
val[k] = stor[j];

}
}


while (k>2) {
for (i=0, j=0 ; j<k ; j++, i++) {
val[i] = (val[j]+val[j+1])%10;
}
if (k==4) {
if (val[0]==1 && val[1]==0 && val[2]==0) {
return 100;
}
}
k--;
}
return 0;
}

int main( void ) {
char input[20];
int i, found, result;
while ( gets(input) ) {

for (i=1, found=0 ; i<=10000 && found==0 ; i++) {
result = y(input, i);
if (result == 100) {
found = 1;
}
}
if (found == 1) {
printf("%d ",i-1);
} else {
printf(":( ");
}
}
return 0;
}

Go to link download

Read more »