您的位置:首页 > 其它

[MZ test.16]P1 评测

2016-05-10 17:44 281 查看
还在忍受 Dev-cpp 吗?反正我是忍不了了!贴吧上有一大神在开发 SmartC++ ,邀请各位 OIer 参与其中,Jiangzh 也信心满满的去报名。不过要想加入其中必须要通过它的考验第一个考验是评测程序的一部分——编译检查

每个程序仅会出现如下语句(每个语句独占一行,并且行首行尾无多余空格,要求内容完全一致)

1
#include<>

无任何空格,<中间为头文件>

2
using namespace std;

3
int main()

int 和 main()之间有一个空格

4
{

5
}

6
int a;

保证程序至多出现一个 32 位整型变量 a

7
long long b;

保证程序至多出现一个 64 位整型变量 b

8
char ch;

保证程序至多出现一个 char 型变量 ch

9
char s[100];

保证程序至多出现一个长度为 100 的 char 型字符串 s

10
memset(s,0,sizeof(s));

11
strcpy(s,”AC”);

12
printf(“%d”,a);

13
printf(“%I64d”,b);

14
scanf(“%d”,&a);

15
scanf(“%I64d”,&b);

16
cin>>a;

17
cin>>b;

18
cout<<a;

19
cout<<b;

20
return 0;

我们需要按照如下规则进行评测,如果有错仅会出现一类错误(需要输出字母的地方均为红色加粗部分):

① 缺少头文件(严格按照 Linux 下 g++进行检查,头文件全部为 C++头文件,无 C 头文件),则输出 N+1 行
第 1 行:输出”head”和一个空格以及一个整数 N

第 2~N+1 行:每行一个字符串,即缺少的头文件(只输出需要的,没有用到

的不输出,按照字典序升序输出)

② 语法错误,只会出现如下情况:

a) 出现上面语句缺少分号的则输出两行

第 1 行:输出” semicolon

第 2 行:一个整数,第一个缺少分号的行号

a) printf, scanf, cin, cout 在读入输出变量的时候变量还未定义,则输出两行

第 1 行:输出”Cannot found!!!”(中间有一个空格)

第 2 行:第一次出错的行号

b) cin, cout 需要 using namespace std; 支持,否则输出两行

第 1 行:输出”Warning std::!!!”(中间有一个空格)

第 2 行:第一个使用 cin, cout 的行号

c) 对整个函数的判断

1. 缺少 int main()输出一行:”Main!!!

2. int main()下面紧接着有一行为”{”,如缺少输出一行:”{

3. 倒数第二行应有”}”,如缺少输出”}

4. 倒数第三行应有一个”return 0;”如缺少输出一行:”return!!!

剩下的其他任何情况均输出一行:”Succeed!!!

[Input]

一个程序,直到文末(最后一行为一个空行)(程序中间无空行和多余空格)

[Output]

按照上面要求输出

[Sample 1]

judge.in

judge.out

int main()

return!!!

{

}

[Sample 2]

judge.in

judge.out

int main()

head 1

{

cstdio

int a;

printf(“%d”,a);

return 0;

}

[Sample 3]

judge.in

judge.out

#include<iostream>

Warning std::!!!

int main()

5

{

int a;

cin>>a;

return 0;

}

[Sample 4]

judge.in

judge.out

#include<iostream>

Succeed!!!

#include<cstdio>

using namespace std;

int main()

{

int a;

long long b;

cin>>a;

printf(“%I64d”,b);

return 0;

}

[Sample 5]

judge.in

judge.out

#include<cstdio>

Cannot found!!!

int main()

4

{

printf("%d",a);

return 0;

}

[Hit]

程序最多 20 行

std:

#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
using std::string;

int n=0;
char s[20][100];
int len[20];

bool semicolon()
{
for(int i=1;i<=n;i++)
{
if(s[i][0]=='#') continue;
if(!strcmp(s[i],"int main()")) continue;
if(s[i][0]=='{') continue;
if(s[i][0]=='}') continue;
if(s[i][0]=='i' && s[i][len[i]-1]==')') continue;
if(s[i][len[i]-1]!=';') {printf("semicolon\n%d\n",i);return 1;}
}
return 0;
}
bool cannot()
{
bool hash_a=0,hash_b=0,hash_ch=0,hash_s=0;
for(int i=1;i<=n;i++)
{
if(!strcmp(s[i],"int a;")) hash_a=1;
if(!strcmp(s[i],"long long b;")) hash_b=1;
if(!strcmp(s[i],"char ch;")) hash_ch=1;
if(!strcmp(s[i],"char s[100];")) hash_s=1;
if(    (s[i][0]=='p' && s[i][len[i]-3]=='a' && !hash_a)
|| (s[i][0]=='p' && s[i][len[i]-3]=='b' && !hash_b)
|| (s[i][0]=='c' && s[i][len[i]-2]=='a' && !hash_a)
|| (s[i][0]=='c' && s[i][len[i]-2]=='b' && !hash_b) )
{
printf("Cannot found!!!\n%d\n",i);
return 1;
}
}
return 0;
}
bool namestd()
{
bool nstd=0;
for(int i=1;i<=n;i++)
{
if(!strcmp(s[i],"using namespace std;")) nstd=1;
if(s[i][0]=='c' && (s[i][1]=='i' || s[i][1]=='o') && !nstd)
{
printf("Warning std::!!!\n%d\n",i);
return 1;
}
}
return 0;
}
bool all()
{
bool m=0,l=0,r=0,re=0;
for(int i=1;i<=n;i++)
{
if(!strcmp(s[i],"int main()")) m=1;
if(!strcmp(s[i],"{")) l=1;
if(!strcmp(s[i],"}")) r=1;
if(!strcmp(s[i],"return 0;")) re=1;
}
if(m==0)
{
printf("Main!!!\n");
return 1;
}
else if(l==0)
{
printf("{\n");
return 1;
}
else if(r==0)
{
printf("}\n");
return 1;
}
else if(re==0)
{
printf("return!!!\n");
return 1;
}
return 0;
}
bool head()//判断cstdio,cstring,iostream
{
bool io=0,io_need=0,str=0,str_need=0,ios=0,ios_need=0;
for(int i=1;i<=n;i++)
{
if(!strcmp(s[i],"#include<cstdio>")) io=1;
if(!strcmp(s[i],"#include<cstring>")) str=1;
if(!strcmp(s[i],"#include<iostream>")) ios=1;
if(s[i][0]=='p' && s[i][1]=='r' && s[i][2]=='i') io_need=1;//printf
if(s[i][0]=='s' && s[i][1]=='c' && s[i][2]=='a') io_need=1;//scanf
if(s[i][0]=='c' && s[i][1]=='i' && s[i][2]=='n') ios_need=1;//cin
if(s[i][0]=='c' && s[i][1]=='o' && s[i][2]=='u') ios_need=1;//cout
if(s[i][0]=='s' && s[i][1]=='t' && s[i][2]=='r') str_need=1;//str...
if(s[i][0]=='m' && s[i][1]=='e' && s[i][2]=='m') str_need=1;//mem...
}
int cnt=0;
string res[10];
if(io_need && !io) res[cnt++]="cstdio";
if(ios_need && !ios) res[cnt++]="iostream";
if(str_need && !str) res[cnt++]="cstring";
if(cnt)
{
std::sort(res,res+cnt);
printf("head %d\n",cnt);
for(int i=0;i<cnt;i++) std::cout<<res[i]<<std::endl;
return 1;
}
return 0;
}

int solve()
{
if(semicolon()) return 0;//分号
if(cannot()) return 0;//未定义
if(namestd()) return 0;//无 namespace std
if(all()) return 0;//判断main,{,},return 0;
if(head()) return 0;
return 1;
}

int main()
{
freopen("judge.in","r",stdin);
freopen("judge.out","w",stdout);
while(fgets(s[++n],80,stdin))
{
len
=strlen(s
);
s
[--len
]='\0';//去掉回车
}
n--;
if(solve()) printf("Succeed!!!\n");
//while(1);
return 0;
}


特殊骗分技巧 [50分]:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
char s[30][100];
int len[30];
int n;
//值为出错的行号
int is_head = 0;
int is_return = 0;
int is_fenhao = 1;
int is_undefine = 0;
int is_usingstd = 0;
int is_zuokuohao = 0;
int is_youkuohao = 0;
int is_needusing = 0;
int is_main = 0;
int main()
{
#define LOC
#ifdef LOC
freopen("judge.in","r",stdin);
freopen("judge.out","w",stdout);
#endif
while(gets(s[++n]))
{
len
=strlen(s
);
len
--;
if(s
[0]=='{')is_zuokuohao=1;
if(s
[0]=='}')is_youkuohao=1;
if(s
[0]=='r')is_return=1;
if(s
[0]=='#')is_head=1;
if(s
[0]=='u'&&s
[1]=='s')is_usingstd=n;
if(s
[4]=='m'&&s
[5]=='a')is_main=1;
if((s
[0]=='c'&&s
[1]=='i')||(s
[0]=='c'&&s
[1]=='o'))
is_needusing=1;
if(s
[len
-1]!=';'&&s
[len
-1]!=')'&&s
[len
-1]!='{'&&s
[len
-1]!='}'&&s
[len
-1]!='>')
is_fenhao=0;
}
n--;//去最后一行
//	cout<<is_zuokuohao;
if(!is_return)
{
cout<<"return!!!";
return 0;
}
else if(!is_main)
{
cout<<"Main!!!";
return 0;
}
else if(is_needusing&&!is_usingstd)
{
cout<<"Warning std::!!!";
cout<<endl<<is_needusing;
return 0;
}
else if(!is_head)
{

cout<<"head "<<1;
return 0;
}
else if(!is_zuokuohao)
{
cout<<"{";
return 0;
}
else if(!is_youkuohao)
{
cout<<"}";
return 0;
}
else
{
cout<<"Succeed!!!";
}
return 0;
}


70分

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
char s[30][100];
int len[30];
int n;
//值为出错的行号
int is_head = 0;
int is_return = 0;
int is_fenhao = 0;
int is_undefine = 0;
int is_usingstd = 0;
int is_zuokuohao = 0;
int is_youkuohao = 0;
int is_needusing = 0;
int is_main = 0;
int main()
{
#define LOC
#ifdef LOC
freopen("judge.in","r",stdin);
freopen("judge.out","w",stdout);
#endif
while(gets(s[++n]))
{
len
=strlen(s
);
//	cout<<s
;
//	cout<<endl<<len
;
len
--;
if(s
[0]=='{')is_zuokuohao=1;
if(s
[0]=='}')is_youkuohao=1;
if(s
[0]=='r')is_return=1;
if(s
[0]=='#')is_head=1;
if(s
[0]=='u'&&s
[1]=='s')is_usingstd=n;
if(s
[4]=='m'&&s
[5]=='a')is_main=1;
if((s
[0]=='c'&&s
[1]=='i')||(s
[0]=='c'&&s
[1]=='o'))
is_needusing=n;
if(s
[len
]!=')'&&s
[len
]!='{'&&s
[len
]!='}'&&s
[len
]!='>')
{
if(s
[len
]!=';')
{
is_fenhao=n;
}
}

}
n--;//去最后一行
//	cout<<is_zuokuohao;
if(!is_return)
{
cout<<"return!!!";
return 0;
}
else if(!is_main)
{
cout<<"Main!!!";
return 0;
}
else if(is_needusing&&!is_usingstd)
{
cout<<"Warning std::!!!";
cout<<endl<<is_needusing;
return 0;
}
else if(!is_head)
{

cout<<"head "<<"5";
cout<<"cstdio";
return 0;
}
else if(!is_zuokuohao)
{
cout<<"{";
return 0;
}
else if(!is_youkuohao)
{
cout<<"}";
return 0;
}
else if(is_fenhao)
{
cout<<"semicolon"<<endl;
cout<<is_fenhao;
}
else
{
cout<<"Succeed!!!";
}
return 0;
}

80' (只有一组数据是关于定义错误的。。woc。。)

大模拟!!

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
char s[30][100];
int len[30];
int n;
//值为出错的行号
int is_head = 0;
int is_return = 0;
int is_fenhao = 0;
int is_undef = 0;
int is_usingstd = 0;
int is_zuokuohao = 0;
int is_youkuohao = 0;
int is_needusing = 0;
int is_main = 0;
int def[10];// 1->a 2->b 3->ch 4->s[]
int inc[10];// 1->cstdio 2->cstring  3->iostream
int first = 0;
void check(int n)
{
if(first)return;
if(s
[4]=='a')def[1]=1;
if(s
[10]=='b')def[2]=1;
if(s
[6]=='h'&&s
[5]=='c')def[3]=1;
if(s
[5]=='s')def[4]=1;
//cin检查
if((s
[0]=='c'&&s
[1]=='i'))
{
if(s
[5]=='a'&&!def[1])
{
is_undef = n;
first = 1;
}
if(s
[5]=='b'&&!def[2])
{
is_undef = n;
first = 1;
}
}
//cout检查
if(s
[0]=='c'&&s
[1]=='o')
{
if(s
[6]=='a'&&!def[1])
{
is_undef = n;
first = 1;
}
if(s
[6]=='b'&&!def[2])
{
is_undef = n;
first = 1;
}
}
//strcpy检查
if(s
[0]=='s'&&s
[1]=='t')
{
if(s
[7]=='s'&&!def[4])
{
is_undef = n;
first = 1;
}

}
if(s
[0]=='s'&&s
[1]=='c')
{
if(s
[15]=='b'&&!def[2])
{
is_undef = n;
first = 1;
}
if(s
[13]=='a'&&!def[1])
{
is_undef = n;
first = 1;
}
}
//printf检查
if(s
[0]=='p')
{
if(s
[14]=='b'&&!def[2])
{
is_undef = n;
first = 1;
}
if(s
[12]=='a'&&!def[1])
{
is_undef = n;
first = 1;
}
}
//memset检查
if(s
[0]=='m')
{
if(s
[7]=='s')
{
if(!def[4])
{
is_undef = n;
first = 1;
}
}
}
}

int main()
{
#define LOC
#ifdef LOC
freopen("judge.in","r",stdin);
freopen("judge.out","w",stdout);
#endif
while(gets(s[++n]))
{
len
=strlen(s
);
//	cout<<s
;
//	cout<<endl<<len
;
len
--;
if(s
[0]=='{')is_zuokuohao=1;
if(s
[0]=='}')is_youkuohao=1;
if(s
[0]=='r')is_return=1;
if(s
[0]=='#')is_head=1;
if(s
[0]=='u'&&s
[1]=='s')is_usingstd=n;
if(s
[4]=='m'&&s
[5]=='a')is_main=1;
if((s
[0]=='c'&&s
[1]=='i')||(s
[0]=='c'&&s
[1]=='o'))
is_needusing=n;
if(s
[len
]!=')'&&s
[len
]!='{'&&s
[len
]!='}'&&s
[len
]!='>')
{
if(s
[len
]!=';')
{
is_fenhao=n;
}
}

//undef检查
check(n);
//函数头文件检查
//	check2(n);
}
n--;//去最后一行
//	cout<<is_zuokuohao;
if(!is_return)
{
cout<<"return!!!";
return 0;
}
else if(!is_main)
{
cout<<"Main!!!";
return 0;
}
else if(is_needusing&&!is_usingstd)
{
cout<<"Warning std::!!!";
cout<<endl<<is_needusing;
return 0;
}
else if(!is_head)
{

cout<<"head "<<"5";
cout<<"cstdio";
return 0;
}
else if(!is_zuokuohao)
{
cout<<"{";
return 0;
}
else if(!is_youkuohao)
{
cout<<"}";
return 0;
}
else if(is_fenhao)
{
cout<<"semicolon"<<endl;
cout<<is_fenhao;
return 0;
}
else if(is_undef)
{
cout<<"Cannot found!!!";
cout<<endl<<is_undef;
return 0;
}
cout<<"Succeed!!!";
return 0;
}


100’

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
char s[30][100];
int len[30];
int n;
//值为出错的行号
int is_return = 0;
int is_fenhao = 0;
int is_undef = 0;
int is_usingstd = 0;
int is_zuokuohao = 0;
int is_youkuohao = 0;
int is_needusing = 0;
int is_main = 0;
int def[10];// 1->a 2->b 3->ch 4->s[]
int needinc[10]; // 1->cstdio 2->cstring  3->iostream
int first = 0;
void check(int n)
{
if(first)return;
if(s
[4]=='a')def[1]=1;
if(s
[10]=='b')def[2]=1;
if(s
[6]=='h'&&s
[5]=='c')def[3]=1;
if(s
[5]=='s')def[4]=1;
//cin检查
if((s
[0]=='c'&&s
[1]=='i'))
{
needinc[3]=1;
if(s
[5]=='a'&&!def[1])
{
is_undef = n;
first = 1;
}
if(s
[5]=='b'&&!def[2])
{
is_undef = n;
first = 1;
}
}
//cout检查
if(s
[0]=='c'&&s
[1]=='o')
{
needinc[3]=1;
if(s
[6]=='a'&&!def[1])
{
is_undef = n;
first = 1;
}
if(s
[6]=='b'&&!def[2])
{
is_undef = n;
first = 1;
}
}
//strcpy检查
if(s
[0]=='s'&&s
[1]=='t')
{
needinc[2]=1;
if(s
[7]=='s'&&!def[4])
{
is_undef = n;
first = 1;
}

}
if(s
[0]=='s'&&s
[1]=='c')
{
needinc[1]=1;
if(s
[15]=='b'&&!def[2])
{
is_undef = n;
first = 1;
}
if(s
[13]=='a'&&!def[1])
{
is_undef = n;
first = 1;
}
}
//printf检查
if(s
[0]=='p')
{
needinc[1]=1;
if(s
[14]=='b'&&!def[2])
{
is_undef = n;
first = 1;
}
if(s
[12]=='a'&&!def[1])
{
is_undef = n;
first = 1;
}
}
//memset检查
if(s
[0]=='m')
{
needinc[2]=1;
if(s
[7]=='s')
{
if(!def[4])
{
is_undef = n;
first = 1;
}
}
}
}
int inc[10];// 1->cstdio 2->cstring  3->iostream
void check2(int n)
{
if(s
[0]=='#')
{
if(s
[len
-1]=='o')
{
inc[1]=1;
}
if(s
[len
-1]=='g')
{
inc[2]=1;
}
if(s
[len
-1]=='m')
{
inc[3]=1;
}
}
}
int main()
{
#define LOC
#ifdef LOC
freopen("judge.in","r",stdin);
freopen("judge.out","w",stdout);
#endif
while(gets(s[++n]))
{
len
=strlen(s
);
//	cout<<s
;
//	cout<<endl<<len
;
len
--;
if(s
[0]=='{')is_zuokuohao=1;
if(s
[0]=='}')is_youkuohao=1;
if(s
[0]=='r')is_return=1;
if(s
[0]=='u'&&s
[1]=='s')is_usingstd=n;
if(s
[4]=='m'&&s
[5]=='a')is_main=1;
if((s
[0]=='c'&&s
[1]=='i')||(s
[0]=='c'&&s
[1]=='o'))
is_needusing=n;
if(s
[len
]!=')'&&s
[len
]!='{'&&s
[len
]!='}'&&s
[len
]!='>')
{
if(s
[len
]!=';')
{
is_fenhao=n;
}
}

//undef检查
check(n);
//函数头文件检查
check2(n);
}
n--;//去最后一行
//	cout<<is_zuokuohao;
//头文件检查
int cnt = 0;
for(int i=1;i<=3;i++)
if(needinc[i]&&!inc[i])cnt++;
if(!is_return)
{
cout<<"return!!!";
return 0;
}
else if(!is_main)
{
cout<<"Main!!!";
return 0;
}
else if(is_needusing&&!is_usingstd)
{
cout<<"Warning std::!!!";
cout<<endl<<is_needusing;
return 0;
}
else if(cnt)
{
cout<<"head "<<cnt<<endl;
if(needinc[1]&&!inc[1])cout<<"cstdio"<<endl;
if(needinc[2]&&!inc[2])cout<<"cstring"<<endl;
if(needinc[3]&&!inc[3])cout<<"iostream"<<endl;
return 0;
}
else if(!is_zuokuohao)
{
cout<<"{";
return 0;
}
else if(!is_youkuohao)
{
cout<<"}";
return 0;
}
else if(is_fenhao)
{
cout<<"semicolon"<<endl;
cout<<is_fenhao;
return 0;
}
else if(is_undef)
{
cout<<"Cannot found!!!";
cout<<endl<<is_undef;
return 0;
}
cout<<"Succeed!!!";
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: