CHEF AND DIGITS SOLUTION
2 posters
Page 1 of 1
CHEF AND DIGITS SOLUTION
It ran of 25 points,share better solutions.
- Code:
import java.util.Arrays;
import java.util.Scanner;
class digits {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int l=sc.nextInt();
int r=sc.nextInt();
int c=0;
int b[]=new int[10];
int v=0,f=0;
for(int i=0;i<10;i++)
{
b[i]=sc.nextInt();
if(b[i]==0)
{
v++;
}
}
if(v==10)
{
for(int i=l;i<=r;i++)
{
String s="";
s+=i;
for(int k=0;k<10;k++)
{
char ch=(char)(k+48);
if(s.indexOf(ch)==-1)
{
f=1;
break;
}
}
if(f==0)
{
c++;
}
}
}
else
{
for(long i=l;i<=r;i++)
{
String s="";
s+=i;
int dig=s.length();
int a[]=new int[dig];
for(int j=0;j<dig;j++)
{
a[j]=(int)s.charAt(j)-48;
}
Arrays.sort(a);
int letter;
f=0;
for(int j=0;j<dig;j++)
{
f=0;
letter=a[j];
int count=0;
while(true)
{
if(j==dig)
break;
if(a[j]==letter)
{
j++;
count++;
}
else
break;
}
j--;
if(b[letter]!=count)
{
continue;
}
else
{
f=1;
break;
}
}
if(f!=1)
{
for(int k=0;k<10;k++)
{
char ch=(char)(k+48);
if(s.indexOf(ch)==-1)
{
if(b[k]==0)
f=1;
}
}
if(f!=1)
{
c++;
}
}
}
}
System.out.println(c);
}
}
}
akarshsomani- Posts : 21
Join date : 2017-04-04
Re: CHEF AND DIGITS SOLUTION
#include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t>0)
{
unsigned long long int l,r,c1=0,k,temp;
scanf("%llu %llu",&l,&r);
int a[10],rem,c,i;
for(i=0;i<10;i++)
scanf("%d",&a[i]);
for(k=l;k<=r;k++)
{
for(i=0;i<10;i++)
{
c=0;
temp=k;
while(temp>0)
{
rem=temp%10;
if(rem==i)
c++;
temp/=10;
}
if(c==a[i])
{
c1++;
break;
}
}
}
printf("%llu\n",(r-l+1-c1));
t--;
}
return 0;
}
int main()
{
int t;
scanf("%d",&t);
while(t>0)
{
unsigned long long int l,r,c1=0,k,temp;
scanf("%llu %llu",&l,&r);
int a[10],rem,c,i;
for(i=0;i<10;i++)
scanf("%d",&a[i]);
for(k=l;k<=r;k++)
{
for(i=0;i<10;i++)
{
c=0;
temp=k;
while(temp>0)
{
rem=temp%10;
if(rem==i)
c++;
temp/=10;
}
if(c==a[i])
{
c1++;
break;
}
}
}
printf("%llu\n",(r-l+1-c1));
t--;
}
return 0;
}
iamdsc_0410- Posts : 14
Join date : 2017-04-11
Age : 26
Location : IIIT Kalyani
Similar topics
» SMARKET SOLUTION
» ROWSOLD SOLUTION
» DISH OF LIFE SOLUTION
» Similar Dishes Solution
» in ipl question.the test case 2nd is wrong.my solution is correct.
» ROWSOLD SOLUTION
» DISH OF LIFE SOLUTION
» Similar Dishes Solution
» in ipl question.the test case 2nd is wrong.my solution is correct.
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|