程序代码:
#include <stdio.h>
int main( void )
{
char answer[1*1024+1]; // 其实题目没交代答案长度
printf( "请输入正确答案:" );
scanf( "%s", answer );
unsigned long long n; // 其实题目没交代n的取值范围
printf( "请输入新生人数(N):" );
scanf( "%llu", &n );
FILE* fout = fopen( "result.txt", "wt" );
for( unsigned long long i=0; i!=n; ++i )
{
char filename[20+5]; // 其实题目没交代n的取值范围,所以文件名最长是多少就无法确定
sprintf( filename, "%llu.txt", 1+i );
char the[ sizeof answer ];
FILE* fin = fopen( filename, "rt" );
fscanf( fin, "%s", the );
fclose( fin );
size_t count = 0;
for( size_t j=0; answer[j]!='\0' && the[j]!='\0'; ++j )
count += answer[j]==the[j];
fprintf( fout, "%zu\n", count*5 ); // 其实题目没交代一题几分
}
fclose( fout );
puts( "结果已保存" );
}