#UVa:11661-Burger Time?

照題目找出最近的兩店的距離即可。

C++(0.092)

/*******************************************************/
/* UVa 11661 Burger Time                               */
/* Author: LanyiKnight [at] knightzone.studio             */
/* Version: 2012/09/20                                 */
/*******************************************************/
#include<iostream>
#include<cstdio>
using namespace std;

int main(){
  int L;
  char road, state;
  int position, distance;
  while( scanf( "%d", &L ) != EOF && L ){
    getchar();
    state = '.';
    position = -1;
    distance = 2000001;
    for( int i = 0 ; i < L ; i++ ){
      road = getchar();
      if( road == 'Z' ) distance = 0;
      if( road != '.' ){
        if( state != road && state != '.' )
          if( i - position < distance ) distance = i - position;
        state = road;
        position = i;
      }
    }
    printf( "%d\n", distance );
  }
  return 0;
}
廣告

Comment

There is no comment on this post. Be the first one.

發表迴響

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料

%d 位部落客按了讚: