codechef program #17:Tanu and Head-bob;codechef program #18:Devu and Grapes


HEADBOB



#1:PROBLEM STATEMENT:
Tanu has got interested in signs and gestures that we use for communication. One such gesture is the head-bob.
When we want to signal "Yes" to someone, we move the head up-and-down. For "No", the head is moved left-and-right, rotating about the vertical axis.
There is a peculiar way of gesturing "Yes", commonly seen in India, by moving head sideways (rotating about the forward-back axis). This is called the Indian head-bob.
Tanu observed many people on the railways station, and made a list of gestures that they made. Usual "Yes" gesture is recorded as "Y", no as "N" and Indian "Yes" gesture as "I". (Assume no foreigner uses the Indian "Yes" gesture and vice-versa). Identify which of them were Indians, which were not Indian, and which one you cannot be sure about.

Input

First line contains T, number of people observed by Tanu.
Each person is described in two lines. First line of the description contains a single integer N, the number of gestures recorded for this person. Next line contains a string of N characters, each character can be "Y", "N" or "I".

Output

For each person, print "INDIAN" if he/she is from India, "NOT INDIAN" if not from India, and "NOT SURE" if the information is insufficient to make a decision.

Constraints

  • For 30 points: 1 ≤ T,N ≤ 100
  • For 70 points: 1 ≤ T,N ≤ 1000

Example

Input:
3
5
NNNYY
6
NNINNI
4
NNNN

Output:

NOT INDIAN
INDIAN
NOT SURE

My Solution:
import java.util.Scanner;


 class Indi {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int counter=sc.nextInt();

for(int i=0;i {
String adams=null;
int counter2=sc.nextInt();

adams=sc.next();

String text = "I";
Boolean found,found1;
String text1 = "Y";

found = adams.contains(text);
found1 = adams.contains(text1);

if(found)
{
System.out.println("INDIAN");
}
else if(found1==true && found==false )
{
System.out.println("NOT INDIAN");
}
else
{
System.out.println("NOT SURE");
}

}
}
}


#2:PROBLEM STATEMENT:
Grapes of Coderpur are very famous. Devu went to the market and saw that there were N people selling grapes. He didn’t like it because things were not very structured. So, he gave a task to Dhinwa to make things better. If Dhinwa successfully completes the task, Devu will be happy.
Devu wants to change the number of grapes in a bucket of zero or more sellers in such a way that the GCDof all the number of grapes is divisible by K. Dhinwa can add or remove any number of grapes from each of the buckets. Adding or removing a grape will be counted as an operation. Also after the operation, none of the seller’s bucket should be empty.
Help Dhinwa in finding the minimum number of operations needed to make Devu happy.

Input

  • First line of input contains an integer T denoting the number of test cases.
  • For each test case, first line will contain an integer N denoting the number of buckets and integer K.
  • Next line contains N space separated integers denoting the number of grapes in each of the bucket.

Output

For each test case, print a single integer representing the answer of that test case.

Constraints

Subtask #1: 10 points
  • 1 ≤ T ≤ 10, 1 ≤ N ,K ≤ 10, 1 ≤ number of grapes in a bucket ≤ 10
Subtask #2: 10 points
  • 1 ≤ T ≤ 10, 1 ≤ N,K ≤ 100, 1 ≤ number of grapes in a bucket ≤ 100
Subtask #3: 80 points
  • 1 ≤ T ≤ 10, 1 ≤ N ≤ 105, 1 ≤ K ≤ 109, 1 number of grapes in a bucket ≤ 109

Example

Input:
2
2 2
3 5
3 7
10 16 18

Output:
2
8

Explanation

For the first test case, add or remove 1 grape in each of the bucket.

For the second test case, remove three grapes in the first bucket, remove two grapes from the second bucket and add three grapes in the third bucket.

My Solution:

import java.util.Scanner;
import java.lang.Math;


 class dev {

public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
for(int i=0;i { int ans=0;
int b=sc.nextInt();
long k=sc.nextLong();
long input[]=new long[b];
for(int j=0;j {
input[j]=sc.nextLong();
}
for(int j=0;j {
long remainder=input[j]%k;
if(input[j]>=k)
{
ans+=Math.min(remainder, k-remainder);
}
else
{
ans+= k-remainder;
}

}
System.out.println(ans);

}
}


}


Posted by lol ik.

Comments

Popular Posts