Coding Discussions
Would you like to react to this message? Create an account in a few clicks or log in to continue.

SMARKET SOLUTION

2 posters

Go down

SMARKET SOLUTION Empty SMARKET SOLUTION

Post by akarshsomani Mon Apr 17, 2017 5:31 pm

It ran only of 10 points.please share better solutions

Code:
import java.util.Scanner;
 
class smarket {
   public static void  main(String args[])
   {
      Scanner sc=new Scanner(System.in);
      
      int t=sc.nextInt();
      while(t-->0)
      {
         
         int n=sc.nextInt();
         int q=sc.nextInt();
         int a[]=new int[n];
         for(int i=0;i<n;i++)
         {
            a[i]=sc.nextInt();
         }
         while(q-->0)
         {
            int l=sc.nextInt();
            int r=sc.nextInt();
            int k=sc.nextInt();
            int count=0,c=0,copy;
            for(int i=l-1;i<r;i++)
            {
               copy=a[i];
               c=0;
               while(copy==a[i])
               {
                  c++;
                  i++;
                  if(i==r)
                  {
                     break;
                  }
                  else
                  {
                     if(copy==a[i])
                     {
                        c++;
                        i++;
                        if(i==r)
                        {
                           break;
                        }
                     }
                  }
               }
               if(c>=k)
               {
                  count++;
               }
               i--;
            }
            System.out.println(count);
         }
      }
   }
}

akarshsomani

Posts : 21
Join date : 2017-04-04

Back to top Go down

SMARKET SOLUTION Empty Re: SMARKET SOLUTION

Post by iamdsc_0410 Tue Apr 18, 2017 6:33 pm

#include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t>0)
{
long int n,q,i;
scanf("%ld %ld",&n,&q);
long int a[n];
for(i=0;i<n;i++)
scanf("%ld",&a[i]);
while(q>0)
{
long int l,r,m,j,c,c1=0,c2,k;
scanf("%ld %ld %ld",&l,&r,&k);
for(j=l-1;j<=r-1;j+=m-j)
{
c=0;
for(m=j;m<=r-1;m++)
{
if(a[m]==a[j])
c++;
else
break;
}
if(c>=k)
c1++;
}
printf("%ld\n",c1);
q--;
}
t--;
}
return 0;
}
iamdsc_0410
iamdsc_0410

Posts : 14
Join date : 2017-04-11
Age : 26
Location : IIIT Kalyani

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum