/* * @(#) msu96_b.c - Problem 'B' ("Trace of figures") solution * of the ACM Programming Contest at the MSU in 1996. * (c) 1998 Ivan Maidanski http://ivmai.chat.ru * Freeware program source. All rights reserved. ** * Language: ANSI C * Tested with: Borland C++ v3.1 * Last modified: 1998-04-04 13:30:00 GMT+04:00 */ /* Input data file: b.dat */ #include /* FILE, EOF, fopen(), fscanf(), printf() */ int a[100],b[100]; int main(void) { int n; int first=1; int i,j; char c; FILE *f=fopen("b.dat","rt"); do { for (n=0;;) { if (fscanf(f,"%*[^\n#0-9]%c",&c)==EOF) c='#'; if (c=='\n' || c=='#') break; a[n++]=c-'0'; } for (b[0]=0,i=1;i=a[i] && b[i-a[i]]>b[i]+1) b[i-a[i]]=b[i]+1; if (i+a[i]b[i]+1) b[i+a[i]]=b[i]+1; } if (n) { if (!first) printf(" "); first=0; if (b[n-1]