UVa 11661 – Burger Time?

#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main(){
	int n,min,lastD,lastR;
	string s;

	while (cin>>n){
		if(n==0 )
			break;

		cin>>s;
		min = 1<<25;

		lastD = lastR = -1;
		for(int i = 0 ; i<n ; i++){
			if(s[i]=='.')
				continue;
			else if (s[i]=='Z'){
				min = 0;
				break;
			}
			else if (s[i]=='D'){
				lastD = i;
				if (i-lastR<min && lastR!= -1)
					min = i-lastR;
			}
			else {
				lastR = i;
				if (i-lastD<min && lastD!=-1)
					min = i-lastD;
			}

		}
		cout<<min<<endl;
	}
	return 0;
}


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s