11661 - Burger Time?

All about problems in Volume 116. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

waheed
New poster
Posts: 6
Joined: Mon Jul 07, 2014 5:55 pm

burger - 11661

Post by waheed »

i got WA help plz

Code: Select all



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class burger {
	public static void main (String []args) throws NumberFormatException, IOException{
		BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
		int l ;
		
		
		 do {
			 boolean flag = false ;
				boolean flag2 = false ;
				int max = 2000000;
			  l = Integer.parseInt(buffer.readLine());
			  if(l == 0)break ;
			  String s = buffer.readLine();
			  int c = 0;
			  for(int i = 0; i<s.length();i++){
	             if(flag2 == false)
					  if (s.charAt(i)=='R'){
						  flag = true ;
						  flag2 = true;}
					  else if (s.charAt(i)=='D'){
						  flag = false ;
					  flag2 = true; }
					  else
						  if (s.charAt(i)=='Z')
							  flag2 = true ;
					  	  
				  if(  flag2 == true)	  
				  switch (s.charAt(i)){
				  case ('Z'): max = 0;break;
				  case ('R'):  {
					  if(flag == true)
						  c =0;
					  else 
						  if(c<max){
					  max = ++c ;
					  c = 0; }
						  else
							  c=0;
					  flag = true ;break;
				  }
				  case ('D'): {
					  if(flag==false)
						  c=0;		 
					  else 
						  if(c<max){
							  max = ++c;
							  c = 0; }  
					       else
						       c=0; 
					  flag = false ;break;
				  }
				  case ('.'):   c++;
				  	  
				  }	
		}System.out.print(max);
		
	}while(l!=0);
	
  
}
}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: burger - 11661

Post by brianfry713 »

Use class Main
Check input and AC output for thousands of problems on uDebug!
waheed
New poster
Posts: 6
Joined: Mon Jul 07, 2014 5:55 pm

Re: burger - 11661

Post by waheed »

i used claSS Main i get WA
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: burger - 11661

Post by brianfry713 »

Use System.out.println() instead of System.out.print()
Check input and AC output for thousands of problems on uDebug!
waheed
New poster
Posts: 6
Joined: Mon Jul 07, 2014 5:55 pm

Re: burger - 11661

Post by waheed »

thaaaaaaaaaaaaaaaaaaaanks :D got accepted
arkhels
New poster
Posts: 4
Joined: Mon Dec 16, 2013 6:32 pm

Re: 11661 - Burger Time?

Post by arkhels »

#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <bitset>

using namespace std;

#define FOR(i,n) for(int(i)=0;(i)<(int)(n);(i)++)
#define FORN(i,a,b,c) for(int(i)=a;i<(int)(b);i+=(c))
#define RES(x,nilai) memset(x,nilai,sizeof(x));
#define pb push_back
#define mp make_pair
#define INF 1000000000

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

ll n,indeksR,indeksD,ans,x;
char s[2000050];

int main() {
//freopen("in.txt","r",stdin);
//freopen("13.txt","w",stdout);
ios_base::sync_with_stdio(false); cin.tie(NULL);
while (cin >> n) {
if (n == 0) {break;}
gets(s); indeksR = indeksD = -1; ans = INF; x = strlen(s);
FOR(i,x) {
if (s == 'R') {indeksR = i;}
if (s == 'D') {indeksD = i;}
if (indeksR != -1 && indeksD != -1) ans = min(ans,abs(indeksR-indeksD));

if (s == 'Z') {ans =0 ; break;}
}
cout << ans << endl;


}

return 0;
}















Stil WA , can anyone help ?
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11661 - Burger Time?

Post by uDebug »

arkhels wrote:Stil WA , can anyone help ?
Couple points

(1) Use code tags to make your code legible.

(2) Have you tried running your code on the sample input provided in the problem statement? When I do, I get the following output

Code: Select all

1000000000
(3) Browse the thread for test cases and try those first. Your code outputs the same thing for the other test case on this thread.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.
kennykarnama
New poster
Posts: 1
Joined: Sat Jun 13, 2015 8:39 pm

Re: 11661 - Burger Time?

Post by kennykarnama »

Code: Select all

#include<stdio.h>
#include<stdlib.h>

struct linklist{
	struct linklist *next;
	char store;
	int pos;
};
int min;
typedef struct linklist linklist;
typedef linklist *node;

void insert(node *head,char s,int p);
void removeAll(node *head);
void display(node *head);
int distance(node *head);
int main(){
	char s[2000001];
	int l;
	int i;
	node head;
	while(1){
		scanf("%d",&l);
		while(getchar()!='\n');
		if(l==0)
			break;
		else{
			
			head=NULL;
			min=2000009;
			gets(s);
			for(i=0;i<l;i++){
				
			 if(s[i]=='R'||s[i]=='D')
					insert(&head,s[i],i);
			else if(s[i]=='Z')
				min=0;
			}
			if(min==0)
				printf("%d\n",min);
			else
			printf("%d\n",distance(&head));
		
			removeAll(&head);
		}
	}
	return 0;
}
void insert(node *head,char s,int p){
	node newData=malloc(sizeof(linklist));
	if(newData!=NULL){
		newData->store=s;
		newData->pos=p;
		if(*head==NULL){
			*head=newData;
			newData->next=NULL;
		}
		else{
			newData->next=*head;
			*head=newData;
		}
	}
}
void removeAll(node *head){
	node t=*head;
	node s=NULL;
	while(t!=NULL){
		*head=t->next;
		t->next=NULL;
		free(t);
		t=*head;
	}
	free(head);
}
void display(node *head){
	node t=*head;
	while(t!=NULL){
		printf("%d ",t->pos);
		t=t->next;
	}
	printf("\n");
}
int distance(node *head){
	node t=*head;
	node s=t->next;
	int x;
	while(s!=NULL){
		
	 if((s->store=='R'&&t->store=='D')){
		x=abs(t->pos - s->pos);
		}
	else if(s->store=='D'&&t->store=='R'){
		x=abs(t->pos - s->pos);
	}
	
		if(x < min)
			min=x;
		t=t->next;
		s=s->next;
	}
	return min;
}
can anyone help why this code gives Runtime error ?
Post Reply

Return to “Volume 116 (11600-11699)”