Page 3 of 3

burger - 11661

Posted: Mon Jul 07, 2014 6:30 pm
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);
	
  
}
}

Re: burger - 11661

Posted: Tue Jul 08, 2014 1:48 am
by brianfry713
Use class Main

Re: burger - 11661

Posted: Thu Jul 10, 2014 3:14 pm
by waheed
i used claSS Main i get WA

Re: burger - 11661

Posted: Thu Jul 10, 2014 6:59 pm
by brianfry713
Use System.out.println() instead of System.out.print()

Re: burger - 11661

Posted: Thu Jul 10, 2014 8:52 pm
by waheed
thaaaaaaaaaaaaaaaaaaaanks :D got accepted

Re: 11661 - Burger Time?

Posted: Tue Sep 16, 2014 1:55 pm
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 ?

Re: 11661 - Burger Time?

Posted: Tue Sep 16, 2014 2:09 pm
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.

Re: 11661 - Burger Time?

Posted: Sun Jul 26, 2015 6:07 am
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 ?