xxxxxxxxxx
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int testCases = sc.nextInt();
int n;
double b;
int[] a;
int count;
for (int i = 1; i <= testCases; i++) {
n = sc.nextInt();
a = new int[n];
b = sc.nextDouble();
for (int j = 0; j < n; j++) {
a[j] = sc.nextInt();
}
Arrays.sort(a);
count = 0;
for (int j = 0; j < n; j++) {
b = b - a[j];
if (b < 0) {
break;
}
count++;
}
System.out.println(String.format("Case #%d :%d", i, count));
}
}
}
xxxxxxxxxx
import java.util.LinkedList;
import java.util.List;
class SuffixTrieNode {
final static int MAX_CHAR = 256;
SuffixTrieNode[] children = new SuffixTrieNode[MAX_CHAR];
List<Integer> indexes;
xxxxxxxxxx
import java.util.LinkedList;
import java.util.List;
class SuffixTrieNode {
final static int MAX_CHAR = 256;
SuffixTrieNode[] children = new SuffixTrieNode[MAX_CHAR];
List<Integer> indexes;
xxxxxxxxxx
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int n,i,j;
int[][] a=new int[50][50];
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[i][j]>10 && a[i][j]!=20)
{
System.out.println("No");
return;
}
}
}
System.out.println("Yes");
}
}
xxxxxxxxxx
void rainbow_loop() { //2
idex++;
ihue = ihue + 10;
if (idex >= LED_COUNT/LED_FIZLINE) {
idex = 0;
}
if (ihue > 255) {
ihue = 0;
}
hsv_to_rgb(ihue*100, thissat, 255, leds[idex]);
LEDSshow();
}
xxxxxxxxxx
#include<iostream>
#include<algorithm>
using namespace std;
int cmp(int &a,int &b)
{
return a>b;
}
int main()
{
int n;
long int b;
long int sum;
int i;
int count;
int cows[20000];
cin>>n>>b;
for(i=0;i<n;i++)
cin>>cows[i];
sort(cows,cows+n,cmp);
sum=0;
count=0;
for(i=0;i<n;i++)
{
if(sum>=b)
break;
sum+=cows[i];
count++;
}
cout<<count<<endl;
return 0;
}
xxxxxxxxxx
import java.math.BigInteger;
import java.util.Scanner;
public class Chooser
{
BigInteger num;
public static BigInteger findNumber(Chooser c)
{
Scanner s = new Scanner(System.in);
while(true)
{
System.out.println("choose a number (greater than zero): ");
c.num = s.nextBigInteger();
if(c.num.compareTo(BigInteger.valueOf(0))>0)
break;
}
return c.num;
}
public String guess(BigInteger number)
{
Scanner s = new Scanner(System.in);
while(true){
System.out.println("enter a guess: ");
this.num = s.nextBigInteger();
if(this.num.compareTo(number) == 0)
return "your answer is correct";
else if(this.num.compareTo(number) == 1)
return "the correct answer is lower";
else// (this.num.compareTo(number)== -1)
return "the correct answer is higher";
}
}
public static void main(String[] args)
{
Chooser choose = new Chooser();
BigInteger num = Chooser.findNumber(choose);
String guess = choose.guess(num);
while(true){
if(!guess.equalsIgnoreCase("your answer is correct"))
{
System.out.println(guess);
guess = choose.guess(num);
}
else
{
System.out.println(guess);
return;
}
}
}
}
xxxxxxxxxx
package train;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("Please enter your name");
Scanner scanner = new Scanner(System.in);
String name = scanner.nextLine();
System.out.println("Welcome" + name);
}
}
xxxxxxxxxx
void main()
{
int a,b,c=1;
scanf("%d",&a);
printf("%d! = ",a);
for (b=a;b>0;b--){
printf("%d * ",b);
c=c*b;
}
printf("\n = %d",c);
}
xxxxxxxxxx
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
HashMap<Integer,Boolean> m = new HashMap<>();
ArrayList<Integer> a = new ArrayList<>();
for(int i=0;i<N;i++)
{
int x = sc.nextInt();
while(m.containsKey(x))
{
x = x + 1;
}
m.put(x,true);
a.add(x);
}
int sum = 0;
for(int i=0; i<a.size();i++)
{
sum = sum + a.get(i);
}
System.out.print(sum);
}