溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

codeforce_New Year and North Pole

發布時間:2020-07-10 04:00:01 來源:網絡 閱讀:431 作者:L_maple 欄目:編程語言

#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;
}

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女