我是個對電腦科學有興趣的學生,我會貼上我的學習歷程及生活心情,也請大大們多多指教。 :)

2015年5月9日 星期六

[UVa] 10188 - Automated Judge Script

題目網址: http://goo.gl/RDc3Ck

題意:
(from luckycat)


解法: 字串處理。

TAG: ad hoc

注意:

程式碼:
/**
* Tittle: 10188 - Automated Judge Script
* Author: Cheng-Shih, Wong
* Date: 2015/05/09
*/
// include files
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
// definitions
#define FOR(i,a,b) for( int i=(a),_n=(b); i<=_n; ++i )
#define clr(x,v) memset( x, v, sizeof(x) )
#define N 20005
// declarations
int ti = 1;
int n, m;
char buf[N], ans[N], test[N];
// functions
bool isDig( char ch )
{
return ('0'<=ch && ch<='9');
}
bool judge( char *s, char *t )
{
// printf( "(%s) (%s)\n", s, t );
while( true ) {
while( *s && !isDig(*s) ) ++s;
while( *t && !isDig(*t) ) ++t;
if( !(*s) && !(*t) ) return true;
if( !(*s) || !(*t) ) return false;
if( *s != *t ) return false;
++s; ++t;
}
}
// main function
int main( void )
{
// input
while( scanf( "%d", &n )==1 && n ) {
gets(buf);
gets(ans);
FOR( i, 1, n-1 ) {
gets(buf);
strcat( ans, "\n" );
strcat( ans, buf );
}
scanf( "%d", &m );
gets(buf);
gets(test);
FOR( i, 1, m-1 ) {
gets(buf);
strcat( test, "\n" );
strcat( test, buf );
}
// solve & output
printf( "Run #%d: ", ti++ );
if( !strcmp(ans,test) ) {
puts("Accepted");
} else if( judge(ans,test) ) {
puts("Presentation Error");
} else {
puts("Wrong Answer");
}
}
return 0;
}

沒有留言:

張貼留言

任何意見都樂意傾聽