首页 > 代码库 > codeforce_New Year and North Pole
codeforce_New Year and North Pole
#include<stdio.h>
#include<string.h>
int main(){
int n; //步骤数
char str[10];
int south=20000,north=0;
int flag=2; //做标记,在北极用2表示,在南极用1表示,在其他地方用0表示
int steps; //步数
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d %s",&steps,str);
//判定执行指令之前是否可继续前进
if( flag==1 ) {
if(strcmp(str,"North")){
printf("NO\n");
return 0;
}
}else if(flag==2){
if(strcmp(str,"South")){
printf("No\n");
return 0;
}
}
//判定执行过程中是否可继续前进
if(!strcmp(str,"North")){
if(steps>north){
printf("NO\n");
return 0;
}
}else if(!strcmp(str,"South")){
if(steps>south){
printf("NO\n");
return 0;
}
}
//继续前进
if(!strcmp(str,"North")){
north-=steps;
south+=steps;
} else if(!strcmp(str,"South")){
north+=steps;
south-=steps;
}
//在南极时
if(north==20000){
flag=1;
}
//在北极时
else if(south==20000){
flag=2;
}else{
flag=0;
}
}
if(north==0){
printf("YES\n");
}else{
printf("NO\n");
}
return 0;
}
codeforce_New Year and North Pole