F1
stringlengths 6
6
| F2
stringlengths 6
6
| label
stringclasses 2
values | text_1
stringlengths 149
20.2k
| text_2
stringlengths 48
42.7k
|
---|---|---|---|---|
A12273 | A10558 | 0 | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Dancing
* Jason Bradley Nel
* 16287398
*/
import java.io.*;
public class Dancing {
public static void main(String[] args) {
In input = new In("input.txt");
int T = Integer.parseInt(input.readLine());
for (int i = 0; i < T; i++) {
System.out.printf("Case #%d: ", i + 1);
int N = input.readInt();
int s = input.readInt();
int p = input.readInt();
int c = 0;//counter for >=p cases
//System.out.printf("N: %d, S: %d, P: %d, R: ", N, s, p);
for (int j = 0; j < N; j++) {
int score = input.readInt();
int q = score / 3;
int m = score % 3;
//System.out.printf("%2d (%d, %d) ", scores[j], q, m);
switch (m) {
case 0:
if (q >= p) {
c++;
} else if (((q + 1) == p) && (s > 0) && (q != 0)) {
c++;
s--;
}
break;
case 1:
if (q >= p) {
c++;
} else if ((q + 1) == p) {
c++;
}
break;
case 2:
if (q >= p) {
c++;
} else if ((q + 1) == p) {
c++;
} else if (((q + 2) == p) && (s > 0)) {
c++;
s--;
}
break;
}
}
//System.out.printf("Best result of %d or higher: ", p);
System.out.println(c);
}
}
}
| import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Scanner;
public class B {
public static void main(String[] args) throws FileNotFoundException {
Scanner scan = new Scanner(new File("B-small-attempt1.in"));
System.setOut(new PrintStream("B-small-attempt1.out"));
int t = scan.nextInt();
for (int c = 0; c < t; c++) {
int n = scan.nextInt(); // num
int s = scan.nextInt(); // surprising
int p = scan.nextInt(); // best result cutoff
int[] totalPoints = new int[n];
for (int i = 0; i < n; i++)
totalPoints[i] = scan.nextInt();
int sUsed = 0;
int ans = 0;
for (int i = 0; i < n; i++) {
int pts = totalPoints[i];
// can it be done normal?
if (pts >= p + (p - 1) * 2)
ans++;
// can it be done surp?
else if (pts >= p + Math.max(p - 2, 0) * 2)
if (sUsed < s) {
ans++;
sUsed++;
}
}
System.out.printf("Case #%d: %d%n", c + 1, ans);
}
}
} |
B20856 | B20108 | 0 | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Happy;
import java.io.*;
import java.math.*;
import java.lang.*;
import java.util.*;
import java.util.Arrays.*;
import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStreamReader;
//import java.io.PrintWriter;
//import java.util.StringTokenizer;
/**
*
* @author ipoqi
*/
public class Happy {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new Happy().haha();
}
public void haha() {
BufferedReader in = null;
BufferedWriter out = null;
try{
in = new BufferedReader(new FileReader("C-large.in"));
out = new BufferedWriter(new FileWriter("LLL.out"));
int T = Integer.parseInt(in.readLine());
System.out.println("T="+T);
//LinkedList<Integer> mm = new LinkedList<Integer>();
//mm.add(new LinkedList<Integer>());
//int[][] mm;
//for(int ii=0;ii<mm.length;ii++){
// mm[0][ii] = 1;
//}
for(int i=0;i<T;i++){
String[] line = in.readLine().split(" ");
int A = Integer.parseInt(line[0]);
int B = Integer.parseInt(line[1]);
//System.out.print(" A = "+A+"\n");
//System.out.print(" B = "+B+"\n");
int ans = 0;
for(int j=A;j<B;j++){
int n=j;
if(n>=10){
String N = Integer.toString(n);
int nlen = N.length();
List<Integer> oks = new ArrayList<Integer>();
for(int k=0;k<nlen-1;k++){
String M = "";
for(int kk=1;kk<=nlen;kk++){
M = M + N.charAt((k+kk)%nlen);
}
int m = Integer.parseInt(M);
//System.out.print(" N = "+N+"\n");
//System.out.print(" M = "+M+"\n");
if(m>n && m<=B) {
boolean isNewOne = true;
for(int kkk=0;kkk<oks.size();kkk++){
//System.out.print(" KKK = "+oks.get(kkk)+"\n");
if(m==oks.get(kkk)){
isNewOne = false;
}
}
if(isNewOne){
//System.out.print(" N = "+N+"\n");
//System.out.print(" M = "+M+"\n");
oks.add(m);
ans++;
}
}
}
}
}
out.write("Case #"+(i+1)+": "+ans+"\n");
System.out.print("Case #"+(i+1)+": "+ans+"\n");
}
in.close();
out.close();
}catch(Exception e){
e.printStackTrace();
try{
in.close();
out.close();
}catch(Exception e1){
e1.printStackTrace();
}
}
System.out.print("YES!\n");
}
} | import java.util.Scanner;
public class RecycledNumbers {
public static int Recycled(int k,int begin,int end){
int length =String.valueOf(k).length();
int inc=0;
int con=(int) Math.pow(10,length);
int div=1;
int temp;
for(int i=1;i<length;i++){
div*=10;
con/=10;
temp=(k%div)*con+(k/div);
if(temp>k){
if(temp>=begin&&temp<=end){
inc++;
}
}
}
return inc;
}
public static int testcase(int begin,int end){
int inc=0;
for(int i=begin;i<=end;i++){
inc+=Recycled(i,begin,end);
}
return inc;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
for(int i=0;i<T;i++){
System.out.println("Case #"+(i+1)+": "+testcase(scan.nextInt(),scan.nextInt()));
}
}
}
|
A20490 | A22218 | 0 | /**
*
*/
package hu.herba.codejam;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
/**
* Base functionality, helper functions for CodeJam problem solver utilities.
*
* @author csorbazoli
*/
public abstract class AbstractCodeJamBase {
private static final String EXT_OUT = ".out";
protected static final int STREAM_TYPE = 0;
protected static final int FILE_TYPE = 1;
protected static final int READER_TYPE = 2;
private static final String DEFAULT_INPUT = "test_input";
private static final String DEFAULT_OUTPUT = "test_output";
private final File inputFolder;
private final File outputFolder;
public AbstractCodeJamBase(String[] args, int type) {
String inputFolderName = AbstractCodeJamBase.DEFAULT_INPUT;
String outputFolderName = AbstractCodeJamBase.DEFAULT_OUTPUT;
if (args.length > 0) {
inputFolderName = args[0];
}
this.inputFolder = new File(inputFolderName);
if (!this.inputFolder.exists()) {
this.showUsage("Input folder '" + this.inputFolder.getAbsolutePath() + "' not exists!");
}
if (args.length > 1) {
outputFolderName = args[1];
}
this.outputFolder = new File(outputFolderName);
if (this.outputFolder.exists() && !this.outputFolder.canWrite()) {
this.showUsage("Output folder '" + this.outputFolder.getAbsolutePath() + "' not writeable!");
} else if (!this.outputFolder.exists() && !this.outputFolder.mkdirs()) {
this.showUsage("Could not create output folder '" + this.outputFolder.getAbsolutePath() + "'!");
}
File[] inputFiles = this.inputFolder.listFiles();
for (File inputFile : inputFiles) {
this.processInputFile(inputFile, type);
}
}
/**
* @return the inputFolder
*/
public File getInputFolder() {
return this.inputFolder;
}
/**
* @return the outputFolder
*/
public File getOutputFolder() {
return this.outputFolder;
}
/**
* @param input
* input reader
* @param output
* output writer
* @throws IOException
* in case input or output fails
* @throws IllegalArgumentException
* in case the given input is invalid
*/
@SuppressWarnings("unused")
protected void process(BufferedReader reader, PrintWriter pw) throws IOException, IllegalArgumentException {
System.out.println("NEED TO IMPLEMENT (reader/writer)!!!");
System.exit(-2);
}
/**
* @param input
* input file
* @param output
* output file (will be overwritten)
* @throws IOException
* in case input or output fails
* @throws IllegalArgumentException
* in case the given input is invalid
*/
protected void process(File input, File output) throws IOException, IllegalArgumentException {
System.out.println("NEED TO IMPLEMENT (file/file)!!!");
System.exit(-2);
}
/**
* @param input
* input stream
* @param output
* output stream
* @throws IOException
* in case input or output fails
* @throws IllegalArgumentException
* in case the given input is invalid
*/
protected void process(InputStream input, OutputStream output) throws IOException, IllegalArgumentException {
System.out.println("NEED TO IMPLEMENT (stream/stream)!!!");
System.exit(-2);
}
/**
* @param type
* @param input
* @param output
*/
private void processInputFile(File input, int type) {
long starttime = System.currentTimeMillis();
System.out.println("Processing '" + input.getAbsolutePath() + "'...");
File output = new File(this.outputFolder, input.getName() + AbstractCodeJamBase.EXT_OUT);
if (type == AbstractCodeJamBase.STREAM_TYPE) {
InputStream is = null;
OutputStream os = null;
try {
is = new FileInputStream(input);
os = new FileOutputStream(output);
this.process(is, os);
} catch (FileNotFoundException e) {
this.showUsage("FileNotFound: " + e.getLocalizedMessage());
} catch (IllegalArgumentException excIA) {
this.showUsage(excIA.getLocalizedMessage());
} catch (Exception exc) {
System.out.println("Program failed: " + exc.getLocalizedMessage());
exc.printStackTrace(System.out);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
System.out.println("Failed to close input: " + e.getLocalizedMessage());
}
}
if (os != null) {
try {
os.close();
} catch (IOException e) {
System.out.println("Failed to close output: " + e.getLocalizedMessage());
}
}
}
} else if (type == AbstractCodeJamBase.READER_TYPE) {
BufferedReader reader = null;
PrintWriter pw = null;
try {
reader = new BufferedReader(new FileReader(input));
pw = new PrintWriter(output);
this.process(reader, pw);
} catch (FileNotFoundException e) {
this.showUsage("FileNotFound: " + e.getLocalizedMessage());
} catch (IllegalArgumentException excIA) {
this.showUsage(excIA.getLocalizedMessage());
} catch (Exception exc) {
System.out.println("Program failed: " + exc.getLocalizedMessage());
exc.printStackTrace(System.out);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
System.out.println("Failed to close input: " + e.getLocalizedMessage());
}
}
if (pw != null) {
pw.close();
}
}
} else if (type == AbstractCodeJamBase.FILE_TYPE) {
try {
this.process(input, output);
} catch (IllegalArgumentException excIA) {
this.showUsage(excIA.getLocalizedMessage());
} catch (Exception exc) {
System.out.println("Program failed: " + exc.getLocalizedMessage());
exc.printStackTrace(System.out);
}
} else {
this.showUsage("Unknown type given: " + type + " (accepted values: 0,1)");
}
System.out.println(" READY (" + (System.currentTimeMillis() - starttime) + " ms)");
}
/**
* Read a single number from input
*
* @param reader
* @param purpose
* What is the purpose of given data
* @return
* @throws IOException
* @throws IllegalArgumentException
*/
protected int readInt(BufferedReader reader, String purpose) throws IOException, IllegalArgumentException {
int ret = 0;
String line = reader.readLine();
if (line == null) {
throw new IllegalArgumentException("Invalid input: line is empty, it should be an integer (" + purpose + ")!");
}
try {
ret = Integer.parseInt(line);
} catch (NumberFormatException excNF) {
throw new IllegalArgumentException("Invalid input: the first line '" + line + "' should be an integer (" + purpose + ")!");
}
return ret;
}
/**
* Read array of integers
*
* @param reader
* @param purpose
* @return
*/
protected int[] readIntArray(BufferedReader reader, String purpose) throws IOException {
int[] ret = null;
String line = reader.readLine();
if (line == null) {
throw new IllegalArgumentException("Invalid input: line is empty, it should be an integer list (" + purpose + ")!");
}
String[] strArr = line.split("\\s");
int len = strArr.length;
ret = new int[len];
for (int i = 0; i < len; i++) {
try {
ret[i] = Integer.parseInt(strArr[i]);
} catch (NumberFormatException excNF) {
throw new IllegalArgumentException("Invalid input: line '" + line + "' should be an integer list (" + purpose + ")!");
}
}
return ret;
}
/**
* Read array of strings
*
* @param reader
* @param purpose
* @return
*/
protected String[] readStringArray(BufferedReader reader, String purpose) throws IOException {
String[] ret = null;
String line = reader.readLine();
if (line == null) {
throw new IllegalArgumentException("Invalid input: line is empty, it should be a string list (" + purpose + ")!");
}
ret = line.split("\\s");
return ret == null ? new String[0] : ret;
}
/**
* Basic usage pattern. Can be overwritten by current implementation
*
* @param message
* Short message, describing the problem with given program
* arguments
*/
protected void showUsage(String message) {
if (message != null) {
System.out.println(message);
}
System.out.println("Usage:");
System.out.println("\t" + this.getClass().getName() + " program");
System.out.println("\tArguments:");
System.out.println("\t\t<input folder>:\tpath of input folder (default: " + AbstractCodeJamBase.DEFAULT_INPUT + ").");
System.out.println("\t\t \tAll files will be processed in the folder");
System.out.println("\t\t<output folder>:\tpath of output folder (default: " + AbstractCodeJamBase.DEFAULT_OUTPUT + ")");
System.out.println("\t\t \tOutput file name will be the same as input");
System.out.println("\t\t \tinput with extension '.out'");
System.exit(-1);
}
}
| package qr2012;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;
public class DancingWithTheGooglers {
public static void main(String[] args) throws Exception {
String fileName = args[0];
DancingWithTheGooglers obj = new DancingWithTheGooglers();
obj.solve(fileName);
}
public void solve(String fileName) throws Exception {
BufferedReader br = new BufferedReader(new FileReader(fileName));
BufferedWriter bw = new BufferedWriter(
new FileWriter(fileName + ".out"));
int T = Integer.parseInt(br.readLine());
for (int i = 0; i < T; i++) {
String str = br.readLine();
StringTokenizer token = new StringTokenizer(str, " ");
int N = Integer.parseInt(token.nextToken());
int S = Integer.parseInt(token.nextToken());
int p = Integer.parseInt(token.nextToken());
int[] t = new int[N];
for (int j = 0; j < N; j++) {
t[j] = Integer.parseInt(token.nextToken());
}
// Arrays.sort(t);
int cnt = 0;
int scnt = 0;
for (int j = N - 1; j >= 0; j--) {
if (t[j] >= 3 * p - 2) {
cnt += 1;
} else if (t[j] >= 3 * p - 4 && t[j] >= 2 && scnt < S) {
cnt += 1;
scnt += 1;
}
}
bw.write("Case #" + (i + 1) + ": ");
bw.write("" + cnt);
bw.write("\r\n");
}
bw.close();
br.close();
}
}
|
A11201 | A10546 | 0 | package CodeJam.c2012.clasificacion;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/**
* Problem
*
* You're watching a show where Googlers (employees of Google) dance, and then
* each dancer is given a triplet of scores by three judges. Each triplet of
* scores consists of three integer scores from 0 to 10 inclusive. The judges
* have very similar standards, so it's surprising if a triplet of scores
* contains two scores that are 2 apart. No triplet of scores contains scores
* that are more than 2 apart.
*
* For example: (8, 8, 8) and (7, 8, 7) are not surprising. (6, 7, 8) and (6, 8,
* 8) are surprising. (7, 6, 9) will never happen.
*
* The total points for a Googler is the sum of the three scores in that
* Googler's triplet of scores. The best result for a Googler is the maximum of
* the three scores in that Googler's triplet of scores. Given the total points
* for each Googler, as well as the number of surprising triplets of scores,
* what is the maximum number of Googlers that could have had a best result of
* at least p?
*
* For example, suppose there were 6 Googlers, and they had the following total
* points: 29, 20, 8, 18, 18, 21. You remember that there were 2 surprising
* triplets of scores, and you want to know how many Googlers could have gotten
* a best result of 8 or better.
*
* With those total points, and knowing that two of the triplets were
* surprising, the triplets of scores could have been:
*
* 10 9 10 6 6 8 (*) 2 3 3 6 6 6 6 6 6 6 7 8 (*)
*
* The cases marked with a (*) are the surprising cases. This gives us 3
* Googlers who got at least one score of 8 or better. There's no series of
* triplets of scores that would give us a higher number than 3, so the answer
* is 3.
*
* Input
*
* The first line of the input gives the number of test cases, T. T test cases
* follow. Each test case consists of a single line containing integers
* separated by single spaces. The first integer will be N, the number of
* Googlers, and the second integer will be S, the number of surprising triplets
* of scores. The third integer will be p, as described above. Next will be N
* integers ti: the total points of the Googlers.
*
* Output
*
* For each test case, output one line containing "Case #x: y", where x is the
* case number (starting from 1) and y is the maximum number of Googlers who
* could have had a best result of greater than or equal to p.
*
* Limits
*
* 1 ⤠T ⤠100. 0 ⤠S ⤠N. 0 ⤠p ⤠10. 0 ⤠ti ⤠30. At least S of the ti values
* will be between 2 and 28, inclusive.
*
* Small dataset
*
* 1 ⤠N ⤠3.
*
* Large dataset
*
* 1 ⤠N ⤠100.
*
* Sample
*
* Input Output 4 Case #1: 3 3 1 5 15 13 11 Case #2: 2 3 0 8 23 22 21 Case #3: 1
* 2 1 1 8 0 Case #4: 3 6 2 8 29 20 8 18 18 21
*
* @author Leandro Baena Torres
*/
public class B {
public static void main(String[] args) throws FileNotFoundException, IOException {
BufferedReader br = new BufferedReader(new FileReader("B.in"));
String linea;
int numCasos, N, S, p, t[], y, minSurprise, minNoSurprise;
linea = br.readLine();
numCasos = Integer.parseInt(linea);
for (int i = 0; i < numCasos; i++) {
linea = br.readLine();
String[] aux = linea.split(" ");
N = Integer.parseInt(aux[0]);
S = Integer.parseInt(aux[1]);
p = Integer.parseInt(aux[2]);
t = new int[N];
y = 0;
minSurprise = p + ((p - 2) >= 0 ? (p - 2) : 0) + ((p - 2) >= 0 ? (p - 2) : 0);
minNoSurprise = p + ((p - 1) >= 0 ? (p - 1) : 0) + ((p - 1) >= 0 ? (p - 1) : 0);
for (int j = 0; j < N; j++) {
t[j] = Integer.parseInt(aux[3 + j]);
if (t[j] >= minNoSurprise) {
y++;
} else {
if (t[j] >= minSurprise) {
if (S > 0) {
y++;
S--;
}
}
}
}
System.out.println("Case #" + (i + 1) + ": " + y);
}
}
}
| package practice;
import java.util.*;
public class GoogleDance {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int cases = Integer.parseInt(sc.nextLine());
for(int i = 0; i<cases; i++){
//Case starts here
int caseCounter = i+1;
String caseLine = sc.nextLine();
String[] caseArray = caseLine.split(" ");
int googlers = Integer.parseInt(caseArray[0]);
int surprising = Integer.parseInt(caseArray[1]);
int passing = Integer.parseInt(caseArray[2]);
List<Integer> scores = new ArrayList<Integer>();
for(int j = 3; j<caseArray.length;j++){
scores.add(Integer.parseInt(caseArray[j]));
}
//Finding individual scores
int result = 0;
for(Integer score:scores){
if(score%3==0){
int individual = score/3;
if(individual==0){
if(individual>=passing){
result++;
}
}else{
if(individual>=passing){
result++;
}else if(surprising>0){
individual++;
if(individual>=passing){
result++;
surprising--;
}
}
}
}
if(score%3==1){
int individual = score/3+1;
if(individual>=passing){
result++;
}
}
if(score%3==2){
int individual = score/3+1;
if(individual>=passing){
result++;
}else if(surprising>0){
individual++;
if(individual>=passing){
result++;
surprising--;
}
}
}
}
System.out.println("Case #"+caseCounter+": " + result);
//Case ends here
}
}
}
|
A10699 | A11846 | 0 | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Dancing {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// read input file
File file = new File("B-small-attempt4.in");
//File file = new File("input.txt");
BufferedReader br = new BufferedReader(new FileReader(file));
String ln = "";
int count = Integer.parseInt(br.readLine());
// write output file
File out = new File("outB.txt");
BufferedWriter bw = new BufferedWriter(new FileWriter(out));
int y = 0;
for (int i=0; i < count; i++){
ln = br.readLine();
y = getY(ln);
bw.write("Case #" + (i+1) + ": " + y);
bw.newLine();
}
bw.close();
}
private static int getY(String str) {
String[] data = str.split(" ");
int n = Integer.parseInt(data[0]);
int s = Integer.parseInt(data[1]);
int p = Integer.parseInt(data[2]);
int[] t = new int[n];
for (int i=0; i < n; i++){
t[i] = Integer.parseInt(data[i+3]);
}
int y = 0;
int base = 0;
for(int j=0; j < t.length; j++){
base = t[j] / 3;
if(base >= p) { y++; }
else if(base == p-1){
if(t[j] - (base+p) > base-1 && t[j] > 0){
y++;
} else if(s>0 && t[j] - (base+p) > base-2 && t[j] > 0){
s -= 1;
y++;
}
} else if(base == p-2){
if(s > 0 && t[j] - (base+p) > base-1 && t[j] > 0){
s -= 1;
y++;
}
}
}
return y;
}
}
|
import java.io.FileNotFoundException;
import java.util.List;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Amya
*/
public class Dancing {
public static void main(String args[]) throws FileNotFoundException{
List<String> lines = FileUtil.readFileByLine("input1");
int records = Integer.parseInt(lines.get(0));
int numOfGooglers = 0;
int numOfSurprises = 0;
int bestScore = 0;
String[] nums = null;
int eligiblesWithSurprise = 0;
int eligiblesWithoutSurprise = 0;
int onBorder = 0;
int finalEligibles = 0;
for(int i = 1; i<=records; i++){
nums = lines.get(i).split(" ");
numOfGooglers = Integer.parseInt(nums[0]);
numOfSurprises = Integer.parseInt(nums[1]);
bestScore = Integer.parseInt(nums[2]);
for(int j=3 ; j<nums.length; j++){
if(Integer.parseInt(nums[j])>=bestScore){
if(Integer.parseInt(nums[j])>=(bestScore*3 - 4)){
eligiblesWithSurprise ++;
}
if(Integer.parseInt(nums[j])>=(bestScore*3 - 2)){
eligiblesWithoutSurprise ++;
}
}
}
finalEligibles = eligiblesWithoutSurprise;
onBorder = eligiblesWithSurprise - eligiblesWithoutSurprise;
if(onBorder > numOfSurprises){
finalEligibles += numOfSurprises;
}else{
finalEligibles += onBorder;
}
if(i == records)
FileUtil.writeOutput("Case #"+i+": "+finalEligibles, true);
else
FileUtil.writeOutput("Case #"+i+": "+finalEligibles, false);
eligiblesWithSurprise = 0;
eligiblesWithoutSurprise = 0;
}
}
}
|
B12762 | B10815 | 0 | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;
/**
*
* @author imgps
*/
public class C {
public static void main(String args[]) throws Exception{
int A,B;
int ctr = 0;
int testCases;
Scanner sc = new Scanner(new FileInputStream("C-small-attempt0.in "));
testCases = sc.nextInt();
int input[][] = new int[testCases][2];
for(int i=0;i<testCases;i++)
{
// System.out.print("Enter input A B: ");
input[i][0] = sc.nextInt();
input[i][1] = sc.nextInt();
}
for(int k=0;k<testCases;k++){
ctr = 0;
A = input[k][0];
B = input[k][1];
for(int i = A;i<=B;i++){
int num = i;
int nMul = 1;
int mul = 1;
int tnum = num/10;
while(tnum > 0){
mul = mul *10;
tnum= tnum/10;
}
tnum = num;
int n = 0;
while(tnum > 0 && mul >= 10){
nMul = nMul * 10;
n = (num % nMul) * mul + (num / nMul);
mul = mul / 10;
tnum = tnum / 10;
for(int m=num;m<=B;m++){
if(n == m && m > num){
ctr++;
}
}
}
}
System.out.println("Case #"+(k+1)+": "+ctr);
}
}
}
| import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class RecycledNumbers {
/**
* @param args
* @throws IOException
* @throws NumberFormatException
*/
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int cases = Integer.parseInt(br.readLine().trim());
for(int t=1;t<=cases;t++){
String[] inp=br.readLine().trim().split(" ");
int start=Integer.parseInt(inp[0]);
int end=Integer.parseInt(inp[1]);
System.out.println("Case #"+t+": "+getAns(start, end));
}
}
public static long getAns(int start, int end){
boolean[] visited=new boolean[end+1];
long total=0;
int max=0;
int digitCount=1;
int mult=10;
while(start/(mult) !=0){
digitCount++;
mult*=10;
}
for(int n=start;n<=end;n++){
int count=1;
if(visited[n])
continue;
visited[n]=true;
for(int s=1;s<digitCount;s++){
int o=n;
int fst=(int) Math.pow(10, s), oth=(int) Math.pow(10, digitCount-s);
int rem=o%fst;
o/=fst;
o+=(rem*oth);
if(o>=start && o<=end && !visited[o]){
if(rem/(Math.pow(10,digitCount-s-1))>0){
if(o!=n){
count++;
visited[o]=true;
}
}
}
}
total+=count*(count-1)/2;
}
return total;
}
}
|
B10149 | B11415 | 0 | import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;
// Recycled Numbers
// https://code.google.com/codejam/contest/1460488/dashboard#s=p2
public class C {
private static String process(Scanner in) {
int A = in.nextInt();
int B = in.nextInt();
int res = 0;
int len = Integer.toString(A).length();
for(int n = A; n < B; n++) {
String str = Integer.toString(n);
TreeSet<Integer> set = new TreeSet<Integer>();
for(int i = 1; i < len; i++) {
int m = Integer.parseInt(str.substring(i, len) + str.substring(0, i));
if ( m > n && m <= B && ! set.contains(m) ) {
set.add(m);
res++;
}
}
}
return Integer.toString(res);
}
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in.available() > 0 ? System.in :
new FileInputStream(Thread.currentThread().getStackTrace()[1].getClassName() + ".practice.in"));
int T = in.nextInt();
for(int i = 1; i <= T; i++)
System.out.format("Case #%d: %s\n", i, process(in));
}
}
| import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
/**
* @author Jelle Prins
*/
public class RecycledNumbers {
public static void main(String[] args) {
String input = "input.txt";
String output = "output.txt";
if (args.length >= 1) {
input = args[0];
if (args.length >= 2) {
output = args[1];
}
}
new RecycledNumbers(input, output);
}
public RecycledNumbers(String inputString, String outputString) {
init();
File input = new File(inputString);
File output = new File(outputString);
if (!input.isFile()) {
System.err.println("input file not found");
System.exit(1);
}
if (output.exists()) {
output.delete();
}
try {
String[] cases = readInput(input);
String[] results = executeCases(cases);
writeOutput(output, results);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
private String[] readInput(File file) throws Exception {
Scanner scanner = new Scanner(file);
int lines = scanner.nextInt();
scanner.nextLine();
String[] cases = new String[lines];
for (int i = 0; i < lines; i++) {
cases[i] = scanner.nextLine().trim();
if (cases[i] == null) {
throw new Exception("not enough input lines");
}
}
scanner.close();
return cases;
}
private String[] executeCases(String[] cases) {
String[] output = new String[cases.length];
for (int i = 0; i < cases.length; i++) {
output[i] = executeCase(i + 1, cases[i]);
}
return output;
}
private String parseOutput(int caseID, String answer) {
String output = "Case #" + caseID + ": " + answer;
System.out.println(output);
return output;
}
private void writeOutput(File output, String[] results) throws Exception {
PrintWriter pw = new PrintWriter(new FileWriter(output));
for (int i = 0; i < results.length; i++) {
pw.println(results[i]);
}
pw.close();
}
private void init() {
}
private String executeCase(int caseID, String input) {
String[] split = input.split(" ");
int start = Integer.parseInt(split[0]);
int end = Integer.parseInt(split[1]);
int answer = 0;
char[] chars;
for (int n = start; n < end; n++) {
chars = getNumberChars(n);
if (chars == null) {
continue;
}
answer += recycle(n, chars, end);
}
return parseOutput(caseID, "" + answer);
}
/**
* Returns null if the number can't be recycled
*/
private char[] getNumberChars(int n) {
if (n < 10) {
return null;
}
char[] chars = Integer.toString(n).toCharArray();
int validChars = 0;
for (char c : chars) {
if (c != '0') {
validChars++;
}
}
if (validChars < 2) {
return null;
}
return chars;
}
private int recycle(int n, char[] chars, int end) {
char[] recycle = new char[chars.length];
Set<String> found = new HashSet<String>();
String str;
int answer;
int recycleTimes = 0;
for (int i = 1; i < chars.length; i++) {
System.arraycopy(chars, i, recycle, 0, chars.length - i);
System.arraycopy(chars, 0, recycle, chars.length - i, i);
str = new String(recycle);
answer = Integer.parseInt(str);
if (answer > n && answer <= end) {
if (found.add(str)) {
recycleTimes++;
}
}
}
return recycleTimes;
}
}
|
B10485 | B12210 | 0 |
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.io.File;
import java.io.IOException;
import java.io.FileWriter;
import java.io.BufferedWriter;
public class Recycle
{
public static void main(String[] args)
{
/* Set<Integer> perms = getPermutations(123456);
for(Integer i: perms)
System.out.println(i);*/
try
{
Scanner s = new Scanner(new File("recycle.in"));
BufferedWriter w = new BufferedWriter(new FileWriter(new File("recycle.out")));
int numCases = s.nextInt();
s.nextLine();
for(int n = 1;n <= numCases; n++)
{
int A = s.nextInt();
int B = s.nextInt();
int count = 0;
for(int k = A; k <= B; k++)
{
count += getNumPairs(k, B);
}
w.write("Case #" + n + ": " + count + "\n");
}
w.flush();
w.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public static int getNumPairs(int n, int B)
{
Set<Integer> possibles = getPermutations(n);
int count = 0;
for(Integer i : possibles)
if(i > n && i <= B)
count++;
return count;
}
public static Set<Integer> getPermutations(int n)
{
Set<Integer> perms = new TreeSet<Integer>();
char[] digits = String.valueOf(n).toCharArray();
for(int firstPos = 1; firstPos < digits.length; firstPos++)
{
String toBuild = "";
for(int k = 0; k < digits.length; k++)
toBuild += digits[(firstPos + k) % digits.length];
perms.add(Integer.parseInt(toBuild));
}
return perms;
}
} | package hk.polyu.cslhu.codejam.solution.impl;
import hk.polyu.cslhu.codejam.solution.Solution;
import java.util.ArrayList;
import java.util.List;
public class StoreCredit extends Solution {
private int amountOfCredits, numOfItems;
private List<Integer> priceList;
@Override
public void setProblem(List<String> testCase) {
this.initial(testCase);
}
private void initial(List<String> testCase) {
// TODO Auto-generated method stub
this.amountOfCredits = Integer.valueOf(testCase.get(0));
this.numOfItems = Integer.valueOf(testCase.get(1));
this.setPriceList(testCase.get(2));
}
private void setPriceList(String string) {
// TODO Auto-generated method stub
String[] splitArray = string.split(" ");
if (splitArray.length != numOfItems)
logger.error("The price list does not include all items ("
+ splitArray.length
+ "/" + this.numOfItems + ")");
this.priceList = new ArrayList<Integer>();
for (String price : splitArray) {
this.priceList.add(Integer.valueOf(price));
}
}
@Override
public void solve() {
for (int itemIndex = 0; itemIndex < this.priceList.size() - 1; itemIndex++) {
for (int anotherItemIndex = itemIndex + 1; anotherItemIndex < this.priceList.size(); anotherItemIndex++) {
if (this.priceList.get(itemIndex) + this.priceList.get(anotherItemIndex) == this.amountOfCredits) {
this.result = (itemIndex + 1) + " " + (anotherItemIndex + 1);
break;
}
}
}
}
@Override
public String getResult() {
return this.result;
}
}
|
A12273 | A11301 | 0 | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Dancing
* Jason Bradley Nel
* 16287398
*/
import java.io.*;
public class Dancing {
public static void main(String[] args) {
In input = new In("input.txt");
int T = Integer.parseInt(input.readLine());
for (int i = 0; i < T; i++) {
System.out.printf("Case #%d: ", i + 1);
int N = input.readInt();
int s = input.readInt();
int p = input.readInt();
int c = 0;//counter for >=p cases
//System.out.printf("N: %d, S: %d, P: %d, R: ", N, s, p);
for (int j = 0; j < N; j++) {
int score = input.readInt();
int q = score / 3;
int m = score % 3;
//System.out.printf("%2d (%d, %d) ", scores[j], q, m);
switch (m) {
case 0:
if (q >= p) {
c++;
} else if (((q + 1) == p) && (s > 0) && (q != 0)) {
c++;
s--;
}
break;
case 1:
if (q >= p) {
c++;
} else if ((q + 1) == p) {
c++;
}
break;
case 2:
if (q >= p) {
c++;
} else if ((q + 1) == p) {
c++;
} else if (((q + 2) == p) && (s > 0)) {
c++;
s--;
}
break;
}
}
//System.out.printf("Best result of %d or higher: ", p);
System.out.println(c);
}
}
}
| import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
public class B{
Scanner sc=new Scanner(System.in);
int INF=1<<28;
double EPS=1e-9;
int caze, T;
int n, s, p;
int[] ts;
void run(){
T=sc.nextInt();
for(caze=1; caze<=T; caze++){
n=sc.nextInt();
s=sc.nextInt();
p=sc.nextInt();
ts=new int[n];
for(int i=0; i<n; i++){
ts[i]=sc.nextInt();
}
solve();
}
}
void solve(){
int count1=0, count2=0, count3=0;
for(int i=0; i<n; i++){
int t=ts[i];
int max1, max2;
if(t%3==0){
max1=t/3;
if(t>=3){
max2=t/3+1;
}else{
max2=t/3;
}
}else if(t%3==1){
max1=max2=t/3+1;
}else{
max1=t/3+1;
max2=t/3+2;
}
max2=min(max2, 10);
if(max1<p&&max2<p){
count1++;
}else if(max1<p&&max2>=p){
count2++;
}else{
count3++;
}
// debug(t, max1, max2, p);
}
int ans=count3+min(count2, s);
answer(ans+"");
}
void answer(String s){
println("Case #"+caze+": "+s);
}
void println(String s){
System.out.println(s);
}
void print(String s){
System.out.print(s);
}
void debug(Object... os){
System.err.println(deepToString(os));
}
public static void main(String[] args){
try{
System.setIn(new FileInputStream("dat/B-small.in"));
System.setOut(new PrintStream(new FileOutputStream(
"dat/B-small.out")));
}catch(Exception e){}
new B().run();
System.out.flush();
System.out.close();
}
}
|
A11917 | A12916 | 0 | package com.silverduner.codejam;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.HashMap;
public class Dancing {
public static void main(String[] args) throws Exception {
File input = new File("B-small-attempt0.in");
BufferedReader in = new BufferedReader(new FileReader(input));
File output = new File("1.out");
BufferedWriter out = new BufferedWriter(new FileWriter(output));
// parse input
int N = Integer.parseInt(in.readLine());
for(int i=0;i<N;i++) {
String str = in.readLine();
out.write("Case #"+(i+1)+": ");
System.out.println("-------");
String[] words = str.split(" ");
int n = Integer.parseInt(words[0]);
int suprise = Integer.parseInt(words[1]);
int threshold = Integer.parseInt(words[2]);
int[] scores = new int[n];
for(int j=0;j<n;j++) {
scores[j] = Integer.parseInt(words[3+j]);
}
int count = 0;
for(int score : scores) {
int a,b,c;
boolean find = false;
boolean sfind = false;
for(a = 10; a>=0 && !find; a--) {
if(3*a-4>score)
continue;
for(b = a; b>=0 && b >=a-2 && !find; b--) {
for(c = b; c>=0 && c >=b-2 && c >=a-2 && !find; c--) {
System.out.println(a+","+b+","+c);
if(a+b+c==score) {
if(a >= threshold) {
if(a-c <= 1){
count++;
find = true;
System.out.println("find!");
}
else if(a-c == 2){
sfind = true;
System.out.println("suprise!");
}
}
}
}
}
}
if(!find && sfind && suprise > 0)
{
count++;
suprise --;
}
}
int maxCount = count;
out.write(maxCount+"\n");
}
out.flush();
out.close();
in.close();
}
}
| package lt.kasrud.gcj.common.io;
import java.io.*;
import java.util.List;
public class Writer {
private static String formatCase(int caseNr, String output){
return String.format("Case #%d: %s", caseNr, output);
}
public static void writeFile(String filename, List<String> data) throws IOException {
BufferedWriter writer = new BufferedWriter(new FileWriter(filename));
for (int i = 0; i < data.size(); i++) {
String output = formatCase(i+1, data.get(i));
writer.write(output + "\n");
}
writer.close();
}
}
|
B11696 | B10003 | 0 | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package recycled;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.TreeSet;
/**
*
* @author Alfred
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
FileInputStream fstream = new FileInputStream("C-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
FileWriter outFile = new FileWriter("out.txt");
PrintWriter out = new PrintWriter(outFile);
String line;
line = br.readLine();
int cases = Integer.parseInt(line);
for (int i=1; i<=cases;i++){
line = br.readLine();
String[] values = line.split(" ");
int A = Integer.parseInt(values[0]);
int B = Integer.parseInt(values[1]);
int total=0;
for (int n=A; n<=B;n++){
TreeSet<String> solutions = new TreeSet<String>();
for (int k=1;k<values[1].length();k++){
String m = circshift(n,k);
int mVal = Integer.parseInt(m);
if(mVal<=B && mVal!=n && mVal> n && !m.startsWith("0") && m.length()==Integer.toString(n).length() )
{
solutions.add(m);
}
}
total+=solutions.size();
}
out.println("Case #"+i+": "+total);
}
in.close();
out.close();
} catch (Exception e) {//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
private static String circshift(int n, int k) {
String nString=Integer.toString(n);
int len=nString.length();
String m = nString.substring(len-k)+nString.subSequence(0, len-k);
//System.out.println(n+" "+m);
return m;
}
}
| package qualification;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.Vector;
public class ProblemC {
static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
int cases = scan.nextInt();
for ( int i = 1; i <= cases; i++ ) {
System.out.println("Case #" + i + ": " + solveCase());
}
}
public static int solveCase() {
int A = scan.nextInt();
int B = scan.nextInt();
Map<Integer, Long> map = new HashMap<Integer, Long>();
Integer[] digits;
for ( int i = A; i <= B; i++ ) {
digits = getDigits(i);
addToMap(digits, map);
}
int result = 0;
for ( Long l : map.values() ) {
result += (l * (l-1)) / 2;
}
return result;
}
public static void addToMap(Integer[] n, Map<Integer, Long> map) {
Vector<Integer> rots = getRotationSymmetricValues(n);
// Remember to handle leading 0! All must have same length
for ( Integer num : rots) {
if ( map.containsKey(num) ) {
map.put(num, map.get(num)+1);
return;
}
}
map.put(digitsToNum(n), 1L);
}
public static Vector<Integer> getRotationSymmetricValues(Integer[] n) {
Vector<Integer> result = new Vector<Integer>();
int origNum = digitsToNum(n);
Queue<Integer> v = new LinkedList<Integer>();
for ( int i = 0; i < n.length; i++ ) {
v.add(n[i]);
}
while (true) {
Integer first = v.poll();
v.add(first);
if ( v.peek() == 0 )
continue;
int num = 0;
for ( Integer i : v) {
num *= 10;
num += i;
}
if ( num == origNum )
break;
result.add(num);
}
return result;
}
public static int digitsToNum(Integer[] digits) {
int num = 0;
for ( int i = 0; i < digits.length; i++ ) {
num *= 10;
num += digits[i];
}
return num;
}
static Comparator<Integer> comp = new Comparator<Integer>() {
@Override
public int compare(Integer arg0, Integer arg1) {
if ( arg0 == 0 )
return 1;
else if ( arg1 == 0)
return -1;
else
return arg0.compareTo(arg1);
}
};
public static Integer[] getDigits(int n) {
int numDigits = (int)Math.log10(n) + 1;
Integer[] digits = new Integer[numDigits];
for ( int i = 0; i < numDigits; i++ ) {
digits[numDigits-1-i] = n % 10;
n /= 10;
}
return digits;
}
}
|
B13196 | B12897 | 0 | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Q3M {
public static void main(String[] args) throws Exception {
compute();
}
private static void compute() throws Exception {
BufferedReader br = new BufferedReader(new FileReader(new File(
"C:\\work\\Q3\\C-small-attempt0.in")));
String line = null;
int i = Integer.parseInt(br.readLine());
List l = new ArrayList();
for (int j = 0; j < i; j++) {
line = br.readLine();
String[] nums = line.split(" ");
l.add(calculate(nums));
}
writeOutput(l);
}
private static int calculate(String[] nums) {
int min = Integer.parseInt(nums[0]);
int max = Integer.parseInt(nums[1]);
int count = 0;
List l = new ArrayList();
for (int i = min; i <= max; i++) {
for (int times = 1; times < countDigits(i); times++) {
int res = shiftNum(i, times);
if (res <= max && i < res) {
if ((!l.contains((i + ":" + res)))) {
l.add(i + ":" + res);
l.add(res + ":" + i);
count++;
}
}
}
}
return count;
}
private static boolean checkZeros(int temp, int res) {
if (temp % 10 == 0 || res % 10 == 0)
return false;
return true;
}
private static int shiftNum(int n, int times) {
int base = (int) Math.pow(10, times);
int temp2 = n / base;
int placeHolder = (int) Math.pow((double) 10,
(double) countDigits(temp2));
int res = placeHolder * (n % base) + temp2;
if (countDigits(res) == countDigits(n)) {
return res;
} else {
return 2000001;
}
}
public static int countDigits(int x) {
if (x < 10)
return 1;
else {
return 1 + countDigits(x / 10);
}
}
private static void writeOutput(List l) throws Exception {
StringBuffer b = new StringBuffer();
int i = 1;
BufferedWriter br = new BufferedWriter(new FileWriter(new File(
"C:\\work\\Q3\\ans.txt")));
for (Iterator iterator = l.iterator(); iterator.hasNext();) {
br.write("Case #" + i++ + ": " + iterator.next());
br.newLine();
}
br.close();
}
} | package exercise;
public class Solver {
private static int[][] MATCHES;
public static Integer[] solve(Integer[][] input) {
Integer[] result = new Integer[input.length];
for (int cnt = 0; cnt < input.length; ++cnt)
result[cnt] = solve(input[cnt]);
return result;
}
public static int solve(Integer[] input) {
if (input == null || input.length < 2)
return 0;
Integer min = input[0];
Integer max = input[1];
int result = 0;
MATCHES = new int[max][4];
for (int cnt = min; cnt < max; ++cnt) {
result += countMatches(cnt, min, max);
}
for (int i = 0; i < MATCHES.length; ++i)
for (int j = 0; j < MATCHES[i].length; ++j)
if (MATCHES[i][j] != 0)
++result;
else
break;
return result;
}
private static int countMatches(int value, int min, int max) {
String string = String.valueOf(value);
int result = 0;
for (int idx = string.length() - 1; idx > 0; --idx) {
String candidateString = string.substring(idx, string.length()) + string.substring(0, idx);
Integer candidate = Integer.parseInt(candidateString);
if (candidate.compareTo(value) > 0
&& candidate.compareTo(min) >= 0
&& candidate.compareTo(max) <= 0) {
addToMatches(value, candidate);
}
}
return result;
}
private static void addToMatches(int value, int match) {
boolean inserted = false;
for (int cnt = 0; cnt < MATCHES[value].length; ++cnt) {
if (MATCHES[value][cnt] == 0) {
MATCHES[value][cnt] = match;
inserted = true;
break;
} else if (MATCHES[value][cnt] == match)
return;
}
if (!inserted) {
int[] save = MATCHES[value];
MATCHES[value] = new int[save.length * 2];
int cnt;
for (cnt = 0; cnt < save.length; ++cnt) {
MATCHES[value][cnt] = save[cnt];
}
MATCHES[value][cnt] = match;
}
}
}
|
B20006 | B20731 | 0 | import java.io.*;
import java.math.BigInteger;
import java.util.*;
import org.jfree.data.function.PowerFunction2D;
public class r2a
{
Map numMap = new HashMap();
int output = 0;
/**
* @param args
*/
public static void main(String[] args)
{
r2a mk = new r2a();
try {
FileInputStream fstream = new FileInputStream("d:/cjinput.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String str;
int i = 0;
while ((str = br.readLine()) != null) {
int begin=0,end = 0;
i++;
if (i == 1)
continue;
mk.numMap = new HashMap();
StringTokenizer strTok = new StringTokenizer(str, " ");
while (strTok.hasMoreTokens()) {
begin = Integer.parseInt(((String) strTok.nextToken()));
end = Integer.parseInt(((String) strTok.nextToken()));
}
mk.evaluate(i, begin, end);
}
in.close();
}
catch (Exception e) {
System.err.println(e);
}
}
private void evaluate(int rowNum, int begin, int end)
{
output=0;
for (int i = begin; i<= end; i++) {
if(numMap.containsKey(Integer.valueOf(i)))
continue;
List l = getPairElems(i);
if (l.size() > 0) {
Iterator itr = l.iterator();
int ctr = 0;
ArrayList tempList = new ArrayList();
while (itr.hasNext()) {
int next = ((Integer)itr.next()).intValue();
if (next <= end && next > i) {
numMap.put(Integer.valueOf(next), i);
tempList.add(next);
ctr++;
}
}
ctr = getCounter(ctr+1,2);
/* if (tempList.size() > 0 || ctr > 0)
System.out.println("DD: " + i + ": " + tempList +" ; ctr = " + ctr);*/
output = output + ctr;
}
}
String outputStr = "Case #" + (rowNum -1) + ": " + output;
System.out.println(outputStr);
}
private int getCounter(int n, int r) {
int ret = 1;
int nfactorial =1;
for (int i = 2; i<=n; i++) {
nfactorial = i*nfactorial;
}
int nrfact =1;
for (int i = 2; i<=n-r; i++) {
nrfact = i*nrfact;
}
return nfactorial/(2*nrfact);
}
private ArrayList getPairElems(int num) {
ArrayList retList = new ArrayList();
int temp = num;
if (num/10 == 0)
return retList;
String str = String.valueOf(num);
int arr[] = new int[str.length()];
int x = str.length();
while (temp/10 > 0) {
arr[x-1] = temp%10;
temp=temp/10;
x--;
}
arr[0]=temp;
int size = arr.length;
for (int pos = size -1; pos >0; pos--) {
if(arr[pos] == 0)
continue;
int pairNum = 0;
int multiplier =1;
for (int c=0; c < size-1; c++) {
multiplier = multiplier*10;
}
pairNum = pairNum + (arr[pos]*multiplier);
for(int ctr = pos+1, i=1; i < size; i++,ctr++) {
if (ctr == size)
ctr=0;
if (multiplier!=1)
multiplier=multiplier/10;
pairNum = pairNum + (arr[ctr]*multiplier);
}
if (pairNum != num)
retList.add(Integer.valueOf(pairNum));
}
return retList;
}
}
| package fixjava;
/**
* Convenience class for declaring a method inside a method, so as to avoid code duplication without having to declare a new method
* in the class. This also keeps functions closer to where they are applied. It's butt-ugly but it's about the best you can do in
* Java.
*/
public interface Lambda2<P, Q, V> {
public V apply(P param1, Q param2);
}
|
B11318 | B11942 | 0 | import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
int casos=1, a, b, n, m, cont;
while(t!=0){
a=sc.nextInt();
b=sc.nextInt();
if(a>b){
int aux=a;
a=b;
b=aux;
}
System.out.printf("Case #%d: ",casos++);
if(a==b){
System.out.printf("%d\n",0);
}else{
cont=0;
for(n=a;n<b;n++){
for(m=n+1;m<=b;m++){
if(isRecycled(n,m)) cont++;
}
}
System.out.printf("%d\n",cont);
}
t--;
}
}
public static boolean isRecycled(int n1, int n2){
String s1, s2, aux;
s1 = String.valueOf( n1 );
s2 = String.valueOf( n2 );
boolean r = false;
for(int i=0;i<s1.length();i++){
aux="";
aux=s1.substring(i,s1.length())+s1.substring(0,i);
// System.out.println(aux);
if(aux.equals(s2)){
r=true;
break;
}
}
return r;
}
}
| import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.HashMap;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
FileInputStream fstream = null;
try {
fstream = new FileInputStream("input.txt");
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
ArrayList<String> plik = new ArrayList<String>();
try {
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println(strLine);
plik.add(strLine);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
plik.remove(0); // counter nie jest potrzebny
int count = 1;
FileWriter writer = null;
try {
writer = new FileWriter("output.txt");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (String s : plik) {
StringBuilder outputString = new StringBuilder("Case #" + count++
+ ": ");
int recycledPairsCount = 0;
String[] splitted = s.split(" ");
Integer A = Integer.parseInt(splitted[0]);
Integer B = Integer.parseInt(splitted[1]);
int a = A;
int b = B;
for (int n = a; n < b; n++) {
for (int m = n + 1; m <= B; m++) {
if (Integer.toString(m).length() != Integer.toString(n)
.length()) {
continue;
}
if (isRecycledPair(n, m)) {
recycledPairsCount += 1;
}
}
}
outputString.append(recycledPairsCount);
System.out.println(outputString);
try {
writer.write(outputString.toString());
writer.write("\r\n");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static boolean isRecycledPair(int n, int m) {
String N = Integer.toString(n);
String M = Integer.toString(m);
int digitNumber = N.length();
if (digitNumber == 1) {
return false;
}
for (int i = 1; i <= digitNumber; i++) {
String temp = N.substring(i, digitNumber);
temp += N.substring(0, i);
if (temp.equals(M)) {
return true;
}
}
return false;
}
}
|
A10793 | A12635 | 0 | import java.io.*;
import java.math.*;
import java.util.*;
import java.text.*;
public class b {
public static void main(String[] args) {
Scanner sc = new Scanner(new BufferedInputStream(System.in));
int T = sc.nextInt();
for (int casenumber = 1; casenumber <= T; ++casenumber) {
int n = sc.nextInt();
int s = sc.nextInt();
int p = sc.nextInt();
int[] ts = new int[n];
for (int i = 0; i < n; ++i)
ts[i] = sc.nextInt();
int thresh1 = (p == 1 ? 1 : (3 * p - 4));
int thresh2 = (3 * p - 2);
int count1 = 0, count2 = 0;
for (int i = 0; i < n; ++i) {
if (ts[i] >= thresh2) {
++count2;
continue;
}
if (ts[i] >= thresh1) {
++count1;
}
}
if (count1 > s) {
count1 = s;
}
System.out.format("Case #%d: %d%n", casenumber, count1 + count2);
}
}
}
| import java.util.*;
public class dancing_googlers {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
int[] answers = new int[T];
for (int c = 0; c < T; c++) {
int N = scanner.nextInt();
int S = scanner.nextInt();
int p = scanner.nextInt();
answers[c] = 0;
for (int i = 0; i < N; i++) {
int t = scanner.nextInt();
if (t >= (p + (p - 1) + (p - 1))) {
answers[c]++;
}
else if ((t >= (p + (p - 1) + (p - 1)) - 2) && (S > 0) && (t > 1) && (t < 29)) {
answers[c]++;
S--;
}
}
}
for (int c = 0; c < T; c++) {
int j = c+1;
System.out.println("Case #"+j+": "+answers[c]);
}
}
}
|
B12762 | B12534 | 0 | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;
/**
*
* @author imgps
*/
public class C {
public static void main(String args[]) throws Exception{
int A,B;
int ctr = 0;
int testCases;
Scanner sc = new Scanner(new FileInputStream("C-small-attempt0.in "));
testCases = sc.nextInt();
int input[][] = new int[testCases][2];
for(int i=0;i<testCases;i++)
{
// System.out.print("Enter input A B: ");
input[i][0] = sc.nextInt();
input[i][1] = sc.nextInt();
}
for(int k=0;k<testCases;k++){
ctr = 0;
A = input[k][0];
B = input[k][1];
for(int i = A;i<=B;i++){
int num = i;
int nMul = 1;
int mul = 1;
int tnum = num/10;
while(tnum > 0){
mul = mul *10;
tnum= tnum/10;
}
tnum = num;
int n = 0;
while(tnum > 0 && mul >= 10){
nMul = nMul * 10;
n = (num % nMul) * mul + (num / nMul);
mul = mul / 10;
tnum = tnum / 10;
for(int m=num;m<=B;m++){
if(n == m && m > num){
ctr++;
}
}
}
}
System.out.println("Case #"+(k+1)+": "+ctr);
}
}
}
| package com.google.codejam;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
public class RecycledNumbers {
public static void main(String argsp[]) throws NumberFormatException, IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("/Users/ashwinjain/Desktop/SmsLogger/InterviewStreet/src/com/google/codejam/in3.txt")));
int cases = Integer.parseInt(br.readLine());
for(int x=0;x<cases;x++){
String temp[] = br.readLine().split(" ");
long a = Long.parseLong(temp[0]);
long b = Long.parseLong(temp[1]);
long c=a;
long count=0;
while(c<=b){
String str= c+"";
HashMap<Long, Boolean> added = new HashMap<Long, Boolean>();
for(int i=1;i<str.length();i++){
long d=Long.parseLong(str.substring(i)+str.substring(0, i));
if(d!=c && d>=a && d<=b && !added.containsKey(d)){
added.put(d, true);
count++;
}
}
c++;
}
System.out.println("Case #"+(x+1)+": "+count/2);
}
}
}
|
B10858 | B10499 | 0 | package be.mokarea.gcj.common;
public abstract class TestCaseReader<T extends TestCase> {
public abstract T nextCase() throws Exception;
public abstract int getMaxCaseNumber();
}
| import java.util.Hashtable;
import java.util.Scanner;
class RecycleResult{
private int lowerBound, upperBound, numberOfDigits;
public RecycleResult(int a, int b, int d){
lowerBound = a;
upperBound = b;
numberOfDigits = d;
}
public int solve(){
int count = 0;
for (int i = lowerBound; i < upperBound; i++){
int p = i;
Hashtable<Integer, Integer> hash = new Hashtable<Integer, Integer>();
for (int j = 1; j < numberOfDigits; j++){
p = moveToFront(p);
if ((p <= upperBound) && (p > i) && (!(p == i)) && (!(hash.containsValue(p)))){
count++;
hash.put(count, p);
}
}
}
return count;
}
public int moveToFront(int z){
int lastDigit = z % 10;
int otherDigits = (z / 10);
for (int i = 0; i < numberOfDigits - 1; i++){
lastDigit = lastDigit * 10;
}
return otherDigits + lastDigit;
}
}
public class Recycle {
public static void main(String[] args) {
int numberOfCases;
Scanner myScanner = new Scanner(System.in);
int a, b;
numberOfCases = myScanner.nextInt();
RecycleResult myResult;
for (int i = 0; i < numberOfCases; i++){
a = myScanner.nextInt();
b = myScanner.nextInt();
int length = String.valueOf(a).length();
myResult = new RecycleResult(a, b, length);
int count = myResult.solve();
System.out.println("Case #" + (i+1) + ": " + count);
}
}
}
|
B10361 | B12861 | 0 | package codejam;
import java.util.*;
import java.io.*;
public class RecycledNumbers {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new FileReader("in.txt"));
PrintWriter out = new PrintWriter(new File("out.txt"));
int T = Integer.parseInt(in.readLine());
for (int t = 1; t <= T; ++t) {
String[] parts = in.readLine().split("[ ]+");
int A = Integer.parseInt(parts[0]);
int B = Integer.parseInt(parts[1]);
int cnt = 0;
for (int i = A; i < B; ++i) {
String str = String.valueOf(i);
int n = str.length();
String res = "";
Set<Integer> seen = new HashSet<Integer>();
for (int j = n - 1; j > 0; --j) {
res = str.substring(j) + str.substring(0, j);
int k = Integer.parseInt(res);
if (k > i && k <= B) {
//System.out.println("(" + i + ", " + k + ")");
if (!seen.contains(k)) {
++cnt;
seen.add(k);
}
}
}
}
out.println("Case #" + t + ": " + cnt);
}
in.close();
out.close();
System.exit(0);
}
}
| package google.codejam;
import java.util.HashMap;
public class RecycledNumberSolver implements GoogleSolver {
@Override
public String solve(String str) {
String [] numbers = str.split(" ");
int min = Integer.parseInt(numbers[0]);
int max = Integer.parseInt(numbers[1]);
int digits = numbers[0].length();
System.out.println("min:"+min + " max:"+ max);
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
int count = 0;
for(int i=min; i<=max ; i++){
for(int move=1 ; move<digits ; move++){
String temp = i+"";
String test = temp.substring(temp.length()-move) + temp.substring(0, temp.length()-move);
int testNum = Integer.parseInt(test);
if(testNum>i && testNum>=min && testNum<=max){
//System.out.println("("+temp + " , " + testNum+ ")");
if(map.get(i)==null || map.get(i)!=testNum){
map.put(i, testNum);
count++;
}
}
}
map.clear();
}
return count+"";
}
}
|
B11327 | B10600 | 0 | package recycledNumbers;
public class OutputData {
private int[] Steps;
public int[] getSteps() {
return Steps;
}
public OutputData(int [] Steps){
this.Steps = Steps;
for(int i=0;i<this.Steps.length;i++){
System.out.println("Test "+(i+1)+": "+Steps[i]);
}
}
}
| import java.io.*;
import java.util.*;
class recycled
{
public static void main(String[] args) throws Exception
{
BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
String inp;
int i,j;
int T=Integer.valueOf(r.readLine());
for(int a=0;a<T;a++)
{
/*consists of a single line containing the integers A and B. */
String[] tmp =r.readLine().split("\\s");
int A = Integer.valueOf(tmp[0]);
int B = Integer.valueOf(tmp[1]);
int y=0;
HashSet<String> stv = new HashSet<String>();
for(i=A;i<=B;i++) {
String s = ""+i;
for(j=1;j<s.length();j++) {
String sj = s.substring(j) + s.substring(0,j);
int k = Integer.valueOf(sj);
String str="("+s+","+sj+")";
if (k>i && k<=B && !stv.contains(str)) {
y++;
stv.add(str);
}
}
}
System.out.println("Case #"+(a+1)+": "+y);
}
}
}
|
A20934 | A20629 | 0 | import java.util.*;
public class B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
B th = new B();
for (int i = 0; i < T; i++) {
int n = sc.nextInt();
int s = sc.nextInt();
int p = sc.nextInt();
int[] t = new int[n];
for (int j = 0; j < n; j++) {
t[j] = sc.nextInt();
}
int c = th.getAnswer(s,p,t);
System.out.println("Case #" + (i+1) + ": " + c);
}
}
public int getAnswer(int s, int p, int[] t) {
int A1 = p + p-1+p-1;
int A2 = p + p-2+p-2;
if (A1 < 0)
A1 = 0;
if (A2 < 0)
A2 = 1;
int remain = s;
int count = 0;
int n = t.length;
for (int i = 0; i < n; i++) {
if (t[i] >= A1) {
count++;
} else if (t[i] < A1 && t[i] >= A2) {
if (remain > 0) {
remain--;
count++;
}
}
}
return count;
}
}
| import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.PrintWriter;
public class bsp2 {
/**
* @param args
* @throws IOException
* @throws NumberFormatException
*/
public static void main(String[] args) throws NumberFormatException, IOException {
// TODO Auto-generated method stub
String inFile = "B-large.in";
String outFile = inFile + ".out";
LineNumberReader lin = new LineNumberReader(new InputStreamReader(new FileInputStream(inFile)));
PrintWriter out = new PrintWriter(new File(outFile));
int NCASE = Integer.parseInt(lin.readLine());
String line="";
int erg=0;
for(int CASE = 1; CASE <= NCASE; CASE++) {
String [] ch=lin.readLine().split(" ");
int googlers=Integer.parseInt(ch[0]);
int sTriplets=Integer.parseInt(ch[1]);
int bResult=Integer.parseInt(ch[2]);
//System.out.println("Case #"+CASE);
//System.out.println(googlers);
//System.out.println(sTriplets);
//System.out.println(bResult);
for(int SCORE=3;SCORE<ch.length;SCORE++){
//System.out.print(ch[SCORE]);
int base=Integer.parseInt(ch[SCORE])/3;
switch(Integer.parseInt(ch[SCORE])%3){
case 0:
if(base >=bResult) erg++;
else{
if(sTriplets>0 && base>0 && base+1 >=bResult){
erg++;
sTriplets--;
}
}
break;
case 1:
if(base>=bResult||base+1>=bResult) erg++;
else{
if(sTriplets>0 && base>0 && base+1 >=bResult){
erg++;
sTriplets--;
}
}
break;
case 2:
if(base+1>=bResult||base>=bResult) erg++;
else{
if(sTriplets>0 && base>0 && base+2 >=bResult){
erg++;
sTriplets--;
}
}
break;
}
}
out.println("Case #" + CASE + ": "+erg);
erg=0;
}
lin.close();
out.close();
}
}
|
B21227 | B20115 | 0 | import java.util.HashSet;
import java.util.Scanner;
public class C {
static HashSet p = new HashSet();
static int low;
static int high;
int count = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int no = sc.nextInt();
for (int i = 1; i <= no; i++) {
p.clear();
low = sc.nextInt();
high = sc.nextInt();
for (int l = low; l <= high; l++) {
recycle(l);
}
System.out.println("Case #" + i + ": " + p.size());
}
}
public static void recycle(int no) {
String s = Integer.toString(no);
for (int i = 0; i < s.length(); i++) {
String rec = s.substring(i) + s.substring(0, i);
int r = Integer.parseInt(rec);
if (r != no && r >= low && r <= high) {
int min = Math.min(r, no);
int max = Math.max(r, no);
String a = Integer.toString(min) + "" + Integer.toString(max);
p.add(a);
}
}
}
}
| import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashSet;
public class CodeJam
{
private static BufferedReader reader;
private static BufferedWriter writer;
public static void main(String args[]) throws Exception
{
prepareFiles("C-large");
int T = Integer.parseInt(reader.readLine());
for(int i = 0; i < T; i++)
{
String[] line = reader.readLine().split(" ");
int A = Integer.parseInt(line[0]);
int B = Integer.parseInt(line[1]);
int l = String.valueOf(A).length();
int recycled = 0;
for(int n = A; n <= B; n++)
{
HashSet<Integer> checkedCycles = new HashSet<>();
String recycledSequence = String.valueOf(n);
for(int j = 1; j < l; j++)
{
recycledSequence = recycle(recycledSequence);
int recycledInt = Integer.valueOf(recycledSequence);
if(checkedCycles.contains(recycledInt))
{
continue;
}
else
{
checkedCycles.add(recycledInt);
}
if(n < recycledInt && recycledInt <= B)
{
recycled ++;
}
}
}
print(getCase(i + 1));
print(recycled);
print("\n");
}
putAwayFiles();
}
private static String recycle(String sequence)
{
String newSequence = new String();
newSequence += sequence.charAt(sequence.length() - 1);
for(int i = 0; i < sequence.length() - 1; i++)
{
newSequence += sequence.charAt(i);
}
return newSequence;
}
private static void prepareFiles(String fileName) throws IOException
{
reader = new BufferedReader(new FileReader(new File(fileName + ".in")));
writer = new BufferedWriter(new FileWriter(new File(fileName + ".out")));
}
private static void putAwayFiles() throws IOException
{
reader.close();
writer.flush();
writer.close();
}
private static String getCase(int i)
{
return "Case #" + i + ": ";
}
private static void print(Object object) throws IOException
{
System.out.print(object.toString());
writer.write(object.toString());
}
}
|
A10699 | A10965 | 0 | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Dancing {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// read input file
File file = new File("B-small-attempt4.in");
//File file = new File("input.txt");
BufferedReader br = new BufferedReader(new FileReader(file));
String ln = "";
int count = Integer.parseInt(br.readLine());
// write output file
File out = new File("outB.txt");
BufferedWriter bw = new BufferedWriter(new FileWriter(out));
int y = 0;
for (int i=0; i < count; i++){
ln = br.readLine();
y = getY(ln);
bw.write("Case #" + (i+1) + ": " + y);
bw.newLine();
}
bw.close();
}
private static int getY(String str) {
String[] data = str.split(" ");
int n = Integer.parseInt(data[0]);
int s = Integer.parseInt(data[1]);
int p = Integer.parseInt(data[2]);
int[] t = new int[n];
for (int i=0; i < n; i++){
t[i] = Integer.parseInt(data[i+3]);
}
int y = 0;
int base = 0;
for(int j=0; j < t.length; j++){
base = t[j] / 3;
if(base >= p) { y++; }
else if(base == p-1){
if(t[j] - (base+p) > base-1 && t[j] > 0){
y++;
} else if(s>0 && t[j] - (base+p) > base-2 && t[j] > 0){
s -= 1;
y++;
}
} else if(base == p-2){
if(s > 0 && t[j] - (base+p) > base-1 && t[j] > 0){
s -= 1;
y++;
}
}
}
return y;
}
}
| package org.tritree_tritree;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class ProblemBSmall {
static private Map<Integer, Integer> MAP_1 = new HashMap<Integer, Integer>();
static private Map<Integer, Integer> MAP_2 = new HashMap<Integer, Integer>();
static {
MAP_1.put(10, 28);
MAP_1.put(9, 25);
MAP_1.put(8, 22);
MAP_1.put(7, 19);
MAP_1.put(6, 16);
MAP_1.put(5, 13);
MAP_1.put(4, 10);
MAP_1.put(3, 7);
MAP_1.put(2, 4);
}
static {
MAP_2.put(10, 26);
MAP_2.put(9, 23);
MAP_2.put(8, 20);
MAP_2.put(7, 17);
MAP_2.put(6, 14);
MAP_2.put(5, 11);
MAP_2.put(4, 8);
MAP_2.put(3, 5);
MAP_2.put(2, 2);
}
public static void main(String[] args) throws IOException {
File source = new File("B-small-attempt0.in");
Scanner scan = new Scanner(source);
int t = scan.nextInt();
scan.nextLine();
List<String> resultList = new ArrayList<String>();
for (int i = 1; i < t + 1; i++) {
int n = scan.nextInt();
int s = scan.nextInt();
int p = scan.nextInt();
int[] pointArray = new int[n];
for (int j = 0; j < n; j++) {
pointArray[j] = scan.nextInt();
}
String result = "Case #" + i + ": " + resolve(s, p, pointArray);
resultList.add(result);
}
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_hhmmss");
File resultFile = new File("B-small-" + dateFormat.format(new Date()) + ".out");
FileOutputStream fileOutputStream = new FileOutputStream(resultFile);
for (String result: resultList) {
result = result + "\n";
fileOutputStream.write(result.getBytes());
}
fileOutputStream.flush();
fileOutputStream.close();
}
private static int resolve(int s, int p, int[] pointArray) {
int cnt = 0;
int remainScnt = s;
for (int i = 0; i < pointArray.length; i++) {
int target = pointArray[i];
if (p*3 -2 <= target) {
cnt++;
} else if (target == 0) {
continue;
} else if (0 < remainScnt) {
if (p*3 -4 <= target) {
cnt++;
remainScnt--;
}
}
}
return cnt;
}
}
|
A22191 | A21491 | 0 | package com.example;
import java.io.IOException;
import java.util.List;
public class ProblemB {
enum Result {
INSUFFICIENT,
SUFFICIENT,
SUFFICIENT_WHEN_SURPRISING
}
public static void main(String[] a) throws IOException {
List<String> lines = FileUtil.getLines("/B-large.in");
int cases = Integer.valueOf(lines.get(0));
for(int c=0; c<cases; c++) {
String[] tokens = lines.get(c+1).split(" ");
int n = Integer.valueOf(tokens[0]); // N = number of Googlers
int s = Integer.valueOf(tokens[1]); // S = number of surprising triplets
int p = Integer.valueOf(tokens[2]); // P = __at least__ a score of P
int sumSufficient = 0;
int sumSufficientSurprising = 0;
for(int i=0; i<n; i++) {
int points = Integer.valueOf(tokens[3+i]);
switch(test(points, p)) {
case SUFFICIENT:
sumSufficient++;
break;
case SUFFICIENT_WHEN_SURPRISING:
sumSufficientSurprising++;
break;
}
// uSystem.out.println("points "+ points +" ? "+ p +" => "+ result);
}
System.out.println("Case #"+ (c+1) +": "+ (sumSufficient + Math.min(s, sumSufficientSurprising)));
// System.out.println();
// System.out.println("N="+ n +", S="+ s +", P="+ p);
// System.out.println();
}
}
private static Result test(int n, int p) {
int fac = n / 3;
int rem = n % 3;
if(rem == 0) {
// int triplet0[] = { fac, fac, fac };
// print(n, triplet0);
if(fac >= p) {
return Result.SUFFICIENT;
}
if(fac > 0 && fac < 10) {
if(fac+1 >= p) {
return Result.SUFFICIENT_WHEN_SURPRISING;
}
// int triplet1[] = { fac+1, fac, fac-1 }; // surprising
// print(n, triplet1);
}
} else if(rem == 1) {
// int triplet0[] = { fac+1, fac, fac };
// print(n, triplet0);
if(fac+1 >= p) {
return Result.SUFFICIENT;
}
// if(fac > 0 && fac < 10) {
// int triplet1[] = { fac+1, fac+1, fac-1 };
// print(n, triplet1);
// }
} else if(rem == 2) {
// int triplet0[] = { fac+1, fac+1, fac };
// print(n, triplet0);
if(fac+1 >= p) {
return Result.SUFFICIENT;
}
if(fac < 9) {
// int triplet1[] = { fac+2, fac, fac }; // surprising
// print(n, triplet1);
if(fac+2 >= p) {
return Result.SUFFICIENT_WHEN_SURPRISING;
}
}
} else {
throw new RuntimeException("error");
}
return Result.INSUFFICIENT;
// System.out.println();
// System.out.println(n +" => "+ div3 +" ("+ rem +")");
}
// private static void print(int n, int[] triplet) {
// System.out.println("n="+ n +" ("+ (n/3) +","+ (n%3) +") => ["+ triplet[0] +","+ triplet[1] +","+ triplet[2] +"]" + (triplet[0]-triplet[2] > 1 ? " *" : ""));
// }
}
| import java.io.*;
import java.util.*;
public class B {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(br.readLine());
int T = sc.nextInt();
int caseNumber = 1;
for(int i=0; i<T; i++){
sc = new Scanner(br.readLine());
int N = sc.nextInt();
int S = sc.nextInt();
int p = sc.nextInt();
int count = 0;
//int countS = 0;
//int countCanBeS = 0;
//ArrayList<Integer> ta = new ArrayList<Integer>();
//ArrayList<Integer> tb = new ArrayList<Integer>();
for(int j=0; j<N; j++){
int tr = sc.nextInt();
if(tr>0){
if(tr/3 >= p){
count++;
}else if((tr + 2)/3 >= p){
count++;
//countCanBeS++;
}else if(tr/3<p){
if(S>0){
if((tr+3)/3 >= p){
count++;
S--;
}else if((tr+4)/3 >= p){
//System.out.println("Hello" + count);
count++;
S--;
}
}
}
}else if(tr==0 && p==0){
count++;
}
}
System.out.println("Case #"+ caseNumber +": "+count);
caseNumber++;
}
}
} |
B20006 | B21343 | 0 | import java.io.*;
import java.math.BigInteger;
import java.util.*;
import org.jfree.data.function.PowerFunction2D;
public class r2a
{
Map numMap = new HashMap();
int output = 0;
/**
* @param args
*/
public static void main(String[] args)
{
r2a mk = new r2a();
try {
FileInputStream fstream = new FileInputStream("d:/cjinput.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String str;
int i = 0;
while ((str = br.readLine()) != null) {
int begin=0,end = 0;
i++;
if (i == 1)
continue;
mk.numMap = new HashMap();
StringTokenizer strTok = new StringTokenizer(str, " ");
while (strTok.hasMoreTokens()) {
begin = Integer.parseInt(((String) strTok.nextToken()));
end = Integer.parseInt(((String) strTok.nextToken()));
}
mk.evaluate(i, begin, end);
}
in.close();
}
catch (Exception e) {
System.err.println(e);
}
}
private void evaluate(int rowNum, int begin, int end)
{
output=0;
for (int i = begin; i<= end; i++) {
if(numMap.containsKey(Integer.valueOf(i)))
continue;
List l = getPairElems(i);
if (l.size() > 0) {
Iterator itr = l.iterator();
int ctr = 0;
ArrayList tempList = new ArrayList();
while (itr.hasNext()) {
int next = ((Integer)itr.next()).intValue();
if (next <= end && next > i) {
numMap.put(Integer.valueOf(next), i);
tempList.add(next);
ctr++;
}
}
ctr = getCounter(ctr+1,2);
/* if (tempList.size() > 0 || ctr > 0)
System.out.println("DD: " + i + ": " + tempList +" ; ctr = " + ctr);*/
output = output + ctr;
}
}
String outputStr = "Case #" + (rowNum -1) + ": " + output;
System.out.println(outputStr);
}
private int getCounter(int n, int r) {
int ret = 1;
int nfactorial =1;
for (int i = 2; i<=n; i++) {
nfactorial = i*nfactorial;
}
int nrfact =1;
for (int i = 2; i<=n-r; i++) {
nrfact = i*nrfact;
}
return nfactorial/(2*nrfact);
}
private ArrayList getPairElems(int num) {
ArrayList retList = new ArrayList();
int temp = num;
if (num/10 == 0)
return retList;
String str = String.valueOf(num);
int arr[] = new int[str.length()];
int x = str.length();
while (temp/10 > 0) {
arr[x-1] = temp%10;
temp=temp/10;
x--;
}
arr[0]=temp;
int size = arr.length;
for (int pos = size -1; pos >0; pos--) {
if(arr[pos] == 0)
continue;
int pairNum = 0;
int multiplier =1;
for (int c=0; c < size-1; c++) {
multiplier = multiplier*10;
}
pairNum = pairNum + (arr[pos]*multiplier);
for(int ctr = pos+1, i=1; i < size; i++,ctr++) {
if (ctr == size)
ctr=0;
if (multiplier!=1)
multiplier=multiplier/10;
pairNum = pairNum + (arr[ctr]*multiplier);
}
if (pairNum != num)
retList.add(Integer.valueOf(pairNum));
}
return retList;
}
}
| import java.io.*;
import java.util.*;
public class C {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
enum InputType {
SAMPLE, SMALL, LARGE;
}
static final InputType currentInputType = InputType.LARGE;
static final int attemptNumber = 0; // for small inputs only
int pow10;
void solve() throws IOException {
int a = nextInt();
int b = nextInt();
pow10 = 1;
int cnt = Integer.toString(a).length();
for (int i = 0; i < cnt - 1; i++)
pow10 *= 10;
long ans = 0;
for (int i = a; i <= b; i++) {
for (int j = (i % 10) * pow10 + (i / 10); j != i; j = (j % 10) * pow10 + j / 10)
if (a <= j && j <= b && j > i)
ans++;
}
out.println(ans);
}
void inp() throws IOException {
switch (currentInputType) {
case SAMPLE:
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
break;
case SMALL:
String fileName = "C-small-attempt" + attemptNumber;
br = new BufferedReader(new FileReader(fileName + ".in"));
out = new PrintWriter(fileName + ".out");
break;
case LARGE:
fileName = "C-large";
br = new BufferedReader(new FileReader(fileName + ".in"));
out = new PrintWriter(fileName + ".out");
break;
}
int test = nextInt();
for (int i = 1; i <= test; i++) {
System.err.println("Running test " + i);
out.print("Case #" + i + ": ");
solve();
}
out.close();
}
public static void main(String[] args) throws IOException {
new C().inp();
}
String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
eof = true;
return null;
}
}
return st.nextToken();
}
String nextString() {
try {
return br.readLine();
} catch (Exception e) {
eof = true;
return null;
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
}
|
B13196 | B10427 | 0 | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Q3M {
public static void main(String[] args) throws Exception {
compute();
}
private static void compute() throws Exception {
BufferedReader br = new BufferedReader(new FileReader(new File(
"C:\\work\\Q3\\C-small-attempt0.in")));
String line = null;
int i = Integer.parseInt(br.readLine());
List l = new ArrayList();
for (int j = 0; j < i; j++) {
line = br.readLine();
String[] nums = line.split(" ");
l.add(calculate(nums));
}
writeOutput(l);
}
private static int calculate(String[] nums) {
int min = Integer.parseInt(nums[0]);
int max = Integer.parseInt(nums[1]);
int count = 0;
List l = new ArrayList();
for (int i = min; i <= max; i++) {
for (int times = 1; times < countDigits(i); times++) {
int res = shiftNum(i, times);
if (res <= max && i < res) {
if ((!l.contains((i + ":" + res)))) {
l.add(i + ":" + res);
l.add(res + ":" + i);
count++;
}
}
}
}
return count;
}
private static boolean checkZeros(int temp, int res) {
if (temp % 10 == 0 || res % 10 == 0)
return false;
return true;
}
private static int shiftNum(int n, int times) {
int base = (int) Math.pow(10, times);
int temp2 = n / base;
int placeHolder = (int) Math.pow((double) 10,
(double) countDigits(temp2));
int res = placeHolder * (n % base) + temp2;
if (countDigits(res) == countDigits(n)) {
return res;
} else {
return 2000001;
}
}
public static int countDigits(int x) {
if (x < 10)
return 1;
else {
return 1 + countDigits(x / 10);
}
}
private static void writeOutput(List l) throws Exception {
StringBuffer b = new StringBuffer();
int i = 1;
BufferedWriter br = new BufferedWriter(new FileWriter(new File(
"C:\\work\\Q3\\ans.txt")));
for (Iterator iterator = l.iterator(); iterator.hasNext();) {
br.write("Case #" + i++ + ": " + iterator.next());
br.newLine();
}
br.close();
}
} | import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
ArrayList<String> answer = read("/home/zehortigoza/Downloads/codejam/c/input.txt");
int tt = 0;
int amount = 1;
for (int i = 0; i < answer.size(); i++) {
String line = answer.get(i);
if (i == 0) {
tt = Integer.parseInt(line);
} else {
if (tt >= amount) {
HashMap<String, Boolean> count = new HashMap<String, Boolean>();
String[] splited = line.split(" ");
String a = splited[0];
String b = splited[1];
int aInt = Integer.parseInt(a);
int bInt = Integer.parseInt(b);
if (! (a.length() == 1 && b.length() == 1)) {
ArrayList<Integer> range = range(aInt, bInt);
for (int z = 0; z < range.size(); z++) {
String currentN = range.get(z)+"";
String currentM = range.get(z)+"";
int length = currentM.length();
for (int j = 0; j < length; j++) {
currentM = currentM.charAt(length-1) + currentM.substring(0, length - 1);
int currentNInt = Integer.parseInt(currentN);
int currentMInt = Integer.parseInt(currentM);
if (currentMInt <= bInt && currentMInt > currentNInt && currentMInt >= aInt) {
if(count.get(currentN+currentM) == null) {
count.put(currentN+currentM, true);
}
}
}
}
}
System.out.println("Case #" + amount + ": " + count.size());
amount++;
}
}
}
}
private static ArrayList<Integer> range(int start, int end) {
ArrayList<Integer> list = new ArrayList<Integer>();
if (start > end) {
System.out.println("error to build range");
return null;
}
for (int i = start; i <= end; i++) {
list.add(i);
}
return list;
}
private static ArrayList<String> read(String url) {
ArrayList<String> lines = new ArrayList<String>();
Scanner scanner = null;
try {
scanner = new Scanner(new FileInputStream(url));
while (scanner.hasNextLine()) {
lines.add(scanner.nextLine());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (scanner != null) {
scanner.close();
}
}
return lines;
}
}
|
A11201 | A12869 | 0 | package CodeJam.c2012.clasificacion;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/**
* Problem
*
* You're watching a show where Googlers (employees of Google) dance, and then
* each dancer is given a triplet of scores by three judges. Each triplet of
* scores consists of three integer scores from 0 to 10 inclusive. The judges
* have very similar standards, so it's surprising if a triplet of scores
* contains two scores that are 2 apart. No triplet of scores contains scores
* that are more than 2 apart.
*
* For example: (8, 8, 8) and (7, 8, 7) are not surprising. (6, 7, 8) and (6, 8,
* 8) are surprising. (7, 6, 9) will never happen.
*
* The total points for a Googler is the sum of the three scores in that
* Googler's triplet of scores. The best result for a Googler is the maximum of
* the three scores in that Googler's triplet of scores. Given the total points
* for each Googler, as well as the number of surprising triplets of scores,
* what is the maximum number of Googlers that could have had a best result of
* at least p?
*
* For example, suppose there were 6 Googlers, and they had the following total
* points: 29, 20, 8, 18, 18, 21. You remember that there were 2 surprising
* triplets of scores, and you want to know how many Googlers could have gotten
* a best result of 8 or better.
*
* With those total points, and knowing that two of the triplets were
* surprising, the triplets of scores could have been:
*
* 10 9 10 6 6 8 (*) 2 3 3 6 6 6 6 6 6 6 7 8 (*)
*
* The cases marked with a (*) are the surprising cases. This gives us 3
* Googlers who got at least one score of 8 or better. There's no series of
* triplets of scores that would give us a higher number than 3, so the answer
* is 3.
*
* Input
*
* The first line of the input gives the number of test cases, T. T test cases
* follow. Each test case consists of a single line containing integers
* separated by single spaces. The first integer will be N, the number of
* Googlers, and the second integer will be S, the number of surprising triplets
* of scores. The third integer will be p, as described above. Next will be N
* integers ti: the total points of the Googlers.
*
* Output
*
* For each test case, output one line containing "Case #x: y", where x is the
* case number (starting from 1) and y is the maximum number of Googlers who
* could have had a best result of greater than or equal to p.
*
* Limits
*
* 1 ⤠T ⤠100. 0 ⤠S ⤠N. 0 ⤠p ⤠10. 0 ⤠ti ⤠30. At least S of the ti values
* will be between 2 and 28, inclusive.
*
* Small dataset
*
* 1 ⤠N ⤠3.
*
* Large dataset
*
* 1 ⤠N ⤠100.
*
* Sample
*
* Input Output 4 Case #1: 3 3 1 5 15 13 11 Case #2: 2 3 0 8 23 22 21 Case #3: 1
* 2 1 1 8 0 Case #4: 3 6 2 8 29 20 8 18 18 21
*
* @author Leandro Baena Torres
*/
public class B {
public static void main(String[] args) throws FileNotFoundException, IOException {
BufferedReader br = new BufferedReader(new FileReader("B.in"));
String linea;
int numCasos, N, S, p, t[], y, minSurprise, minNoSurprise;
linea = br.readLine();
numCasos = Integer.parseInt(linea);
for (int i = 0; i < numCasos; i++) {
linea = br.readLine();
String[] aux = linea.split(" ");
N = Integer.parseInt(aux[0]);
S = Integer.parseInt(aux[1]);
p = Integer.parseInt(aux[2]);
t = new int[N];
y = 0;
minSurprise = p + ((p - 2) >= 0 ? (p - 2) : 0) + ((p - 2) >= 0 ? (p - 2) : 0);
minNoSurprise = p + ((p - 1) >= 0 ? (p - 1) : 0) + ((p - 1) >= 0 ? (p - 1) : 0);
for (int j = 0; j < N; j++) {
t[j] = Integer.parseInt(aux[3 + j]);
if (t[j] >= minNoSurprise) {
y++;
} else {
if (t[j] >= minSurprise) {
if (S > 0) {
y++;
S--;
}
}
}
}
System.out.println("Case #" + (i + 1) + ": " + y);
}
}
}
|
import java.util.Scanner;
public class CodeJam12B {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
for (int zz = 1; zz <= T; zz++) {
int N = in.nextInt();
int S = in.nextInt();
int p = in.nextInt();
int[] t = new int[N];
int out = 0;
for (int i = 0; i < N; i++) {
t[i] = in.nextInt();
t[i] = t[i] - p;
if (t[i] >= 0) {
if (t[i] >= 2 * (p - 1)) {
out++;
} else if (t[i] >= 2 * (p - 2) && S > 0) {
S--;
out++;
}
}
}
System.out.format("Case #%d: %d\n", zz, out);
}
}
}
|
A22642 | A22764 | 0 | import java.util.*;
import java.io.*;
public class DancingWithTheGooglers
{
public DancingWithTheGooglers()
{
Scanner inFile = null;
try
{
inFile = new Scanner(new File("inputB.txt"));
}
catch(Exception e)
{
System.out.println("Problem opening input file. Exiting...");
System.exit(0);
}
int t = inFile.nextInt();
int [] results = new int [t];
DancingWithTheGooglersMax [] rnc = new DancingWithTheGooglersMax[t];
int i, j;
int [] scores;
int s, p;
for(i = 0; i < t; i++)
{
scores = new int [inFile.nextInt()];
s = inFile.nextInt();
p = inFile.nextInt();
for(j = 0; j < scores.length; j++)
scores[j] = inFile.nextInt();
rnc[i] = new DancingWithTheGooglersMax(i, scores, s, p, results);
rnc[i].start();
}
inFile.close();
boolean done = false;
while(!done)
{
done = true;
for(i = 0; i < t; i++)
if(rnc[i].isAlive())
{
done = false;
break;
}
}
PrintWriter outFile = null;
try
{
outFile = new PrintWriter(new File("outputB.txt"));
}
catch(Exception e)
{
System.out.println("Problem opening output file. Exiting...");
System.exit(0);
}
for(i = 0; i < results.length; i++)
outFile.printf("Case #%d: %d\n", i+1, results[i]);
outFile.close();
}
public static void main(String [] args)
{
new DancingWithTheGooglers();
}
private class DancingWithTheGooglersMax extends Thread
{
int id;
int s, p;
int [] results, scores;
public DancingWithTheGooglersMax(int i, int [] aScores, int aS, int aP,int [] res)
{
id = i;
s = aS;
p = aP;
results = res;
scores = aScores;
}
public void run()
{
int a = 0, b = 0;
if(p == 0)
results[id] = scores.length;
else if(p == 1)
{
int y;
y = 3*p - 3;
for(int i = 0; i < scores.length; i++)
if(scores[i] > y)
a++;
else if(scores[i] > 0)
b++;
b = Math.min(b, s);
results[id] = a+b;
}
else
{
int y, z;
y = 3*p - 3;
z = 3*p - 5;
for(int i = 0; i < scores.length; i++)
if(scores[i] > y)
a++;
else if(scores[i] > z)
b++;
b = Math.min(b, s);
results[id] = a+b;
}
}
}
} | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package google_code_jam;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;
/**
*
* @author lenovo
*/
public class B {
public static void main(String[] args) throws IOException {
// TODO code application logic here
BufferedReader br = new BufferedReader(new FileReader("B-large.in"));
PrintWriter pw = new PrintWriter("B.out" );
StringTokenizer st=new StringTokenizer(br.readLine());
// System.out.println(st);
int x = Integer.parseInt(st.nextToken());
a1:for (int i = 0; i < x; i++) {
st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());// number of players
int s = Integer.parseInt(st.nextToken());//number of surprising
int p = Integer.parseInt(st.nextToken());// best degree required
int count=0;//
for (int j = 0; j < n; j++) {
int temp=Integer.parseInt(st.nextToken());
int rem=temp%3;
int div=temp/3;
if(temp==0 && p!=0)continue;
else if(temp==0 && p==0){
count++;
continue;
}
if(rem==0){
if(div>=p){
count++;
continue;
}
else if(div+1>=p && s>0){
count++;
s--;
continue;
}
}// end of this condition
else{
if(rem==1){
if(div+1 >=p)count++;
}
else if(rem==2){
if(div+1 >= p)count++;
else if (div+2 >=p && s>0){
count++;
s--;
continue;
}
}
}
}// End of converting
pw.append("Case #"+(i+1)+": "+count+"\n");
}
pw.close();
}
}
|
A21557 | A21489 | 0 | import java.io.*;
import java.util.*;
public class DancingWithGooglers {
public static class Googlers {
public int T;
public int surp;
public boolean surprising;
public boolean pSurprising;
public boolean antiSurprising;
public boolean pAntiSurprising;
public Googlers(int T, int surp) {
this.T = T;
this.surp = surp;
}
public void set(int a, int b, int c) {
if (c >= 0 && (a + b + c) == T) {
int diff = (Math.max(a, Math.max(b, c)) - Math.min(a, Math.min(b, c)));
if (diff <= 2) {
if (diff == 2) {
if (a >= surp || b >= surp || c >= surp) {
pSurprising = true;
} else {
surprising = true;
}
} else {
if (a >= surp || b >= surp || c >= surp) {
pAntiSurprising = true;
} else {
antiSurprising = true;
}
}
}
}
}
}
public static void main(String... args) throws IOException {
// BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
BufferedReader reader = new BufferedReader(new FileReader("B-large.in"));
// PrintWriter writer = new PrintWriter(System.out);
PrintWriter writer = new PrintWriter("B-large.out");
int len, cases = Integer.parseInt(reader.readLine());
List<Googlers> satisfied = new ArrayList<Googlers>();
List<Googlers> unsatisfied = new ArrayList<Googlers>();
String[] inputs;
int N, S, p;
for (int i = 1; i <= cases; i++) {
inputs = reader.readLine().split(" ");
p = Integer.parseInt(inputs[1]);
S = Integer.parseInt(inputs[2]);
satisfied.clear();
unsatisfied.clear();
for (int j = 3; j < inputs.length; j++) {
int t = Integer.parseInt(inputs[j]);
Googlers googlers = new Googlers(t, S);
for (int k = 0; k <= 10; k++) {
int till = k + 2 > 10 ? 10 : k + 2;
for (int l = k; l <= till; l++) {
googlers.set(k, l, (t - (k + l)));
}
}
if (googlers.pAntiSurprising) {
satisfied.add(googlers);
} else {
unsatisfied.add(googlers);
}
}
int pSurprising = 0;
if (p > 0) {
for (Iterator<Googlers> iter = unsatisfied.iterator(); iter.hasNext(); ) {
Googlers googlers = iter.next();
if (googlers.pSurprising) {
pSurprising++;
iter.remove();
p--;
if (p <= 0) break;
}
}
}
if(p > 0){
for (Iterator<Googlers> iter = unsatisfied.iterator(); iter.hasNext(); ) {
Googlers googlers = iter.next();
if (googlers.surprising) {
iter.remove();
p--;
if (p <= 0) break;
}
}
}
if(p > 0){
for (Iterator<Googlers> iter = satisfied.iterator(); iter.hasNext(); ) {
Googlers googlers = iter.next();
if (googlers.pSurprising) {
iter.remove();
pSurprising++;
p--;
if (p <= 0) break;
}
}
}
if(p > 0){
for (Iterator<Googlers> iter = satisfied.iterator(); iter.hasNext(); ) {
Googlers googlers = iter.next();
if (googlers.surprising) {
iter.remove();
p--;
if (p <= 0) break;
}
}
}
if(p > 0){
writer.print("Case #" + i + ": 0");
}else {
writer.print("Case #" + i + ": " + (satisfied.size() + pSurprising));
}
writer.println();
}
writer.flush();
}
}
| package world2012.qualification;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.Scanner;
public class B {
public static boolean canPass(int[] t, int p) {
if (t[0] < 0 || t[1] < 0 || t[2] < 0)
return false;
return t[0] >= p || t[1] >= p || t[2] >= p;
}
public static int maxGooglers(int[] scores, int p, int s) {
B b = new B();
Triple[] ts = new Triple[scores.length];
for (int i = 0; i < scores.length; i++) {
ts[i] = b.new Triple(scores[i]);
}
int count = 0;
int surpr = 0;
for (Triple t : ts) {
if (canPass(t.triple, p))
count++;
else if (canPass(t.sTriple, p))
surpr++;
}
return count + Math.min(surpr, s);
}
static PrintWriter out;
public static void parseInput() throws Exception {
// String file = "world2012/qualification/B-large-attempt0.in";
String file = "world2012/qualification/B-large.in";
// String file = "input.in";
Scanner scanner = new Scanner(new File(file));
out = new PrintWriter(new FileWriter((file.replaceAll(".in", ""))));
int T = Integer.parseInt(scanner.nextLine());
for (int i = 0; i < T; i++) {
String[] in = scanner.nextLine().split("\\s");
int N = Integer.parseInt(in[0]);
int S = Integer.parseInt(in[1]);
int P = Integer.parseInt(in[2]);
int[] scores = new int[N];
for (int j = 0; j < N; j++) {
scores[j] = Integer.parseInt(in[j + 3]);
}
int r = maxGooglers(scores, P, S);
out.println("Case #"+(i+1)+": "+r+"");
}
}
public static void main(String[] args) throws Exception {
parseInput();
out.close();
System.out.println("Done!");
}
class Triple {
int[] triple;
int[] sTriple;
int score;
public Triple(int score) {
this.score = score;
init();
}
private void init() {
if (score % 3 == 2) {
int l = score / 3;
int b = score / 3 + 1;
triple = new int[] {b, b, l};
sTriple = new int[] {b + 1, b - 1, l};
} else if (score % 3 == 1) {
int l = score / 3;
int b = score / 3 + 1;
triple = new int[] {b, l, l};
sTriple = new int[] {b, b, l - 1};
} else {
int l = score / 3;
triple = new int[] {l, l, l};
sTriple = new int[] {l + 1, l, l - 1};
}
}
}
}
|
B10858 | B10094 | 0 | package be.mokarea.gcj.common;
public abstract class TestCaseReader<T extends TestCase> {
public abstract T nextCase() throws Exception;
public abstract int getMaxCaseNumber();
}
| import java.io.*;
import java.util.*;
public class C implements Runnable{
public void run(){
try{
Scanner in = new Scanner(new File("C-small.in"));
PrintWriter out = new PrintWriter("C-small.out");
int a, b, t = in.nextInt(), ans, x, l;
String min, buf, max;
Set<String> set = new HashSet<String>();
for (int k = 1; k <= t; k++){
ans = 0;
a = in.nextInt();
b = in.nextInt();
max = Integer.toString(b);
for (int i = a; i < b; i++){
set.clear();
x = i;
min = buf = Integer.toString(x);
l = min.length();
for (int j = 0; j < l-1; j++){
buf = min.substring(l - j - 1) + min.substring(0, Math.max(0, l - j - 1));
if ((buf.length() == l) && (min.compareTo(buf) < 0) && (buf.compareTo(max) <= 0)) {
if (!set.contains(buf)){
set.add(buf);
ans++;
}
}
}
}
out.println("Case #" + k + ": " + ans);
}
out.close();
}
catch(Exception e){
}
}
public static void main(String[] args){
(new Thread(new C())).start();
}
} |
B21968 | B20136 | 0 | import java.util.*;
import java.io.*;
public class recycled_numbers {
public static void main(String[]a) throws Exception{
Scanner f = new Scanner(new File(a[0]));
int result=0;
int A,B;
String n,m;
HashSet<String> s=new HashSet<String>();
int T=f.nextInt(); //T total case count
for (int t=1; t<=T;t++){//for each case t
s.clear();
result=0; //reset
A=f.nextInt();B=f.nextInt(); //get values for next case
if (A==B)result=0;//remove case not meeting problem limits
else{
for(int i=A;i<=B;i++){//for each int in range
n=Integer.toString(i);
m=new String(n);
//System.out.println(n);
for (int j=1;j<n.length();j++){//move each digit to the front & test
m = m.substring(m.length()-1)+m.substring(0,m.length()-1);
if(m.matches("^0+[\\d]+")!=true &&
Integer.parseInt(m)<=B &&
Integer.parseInt(n)<Integer.parseInt(m)){
s.add(new String(n+","+m));
//result++;
//System.out.println(" matched: "+m);
}
}
}
result = s.size();
}
//display output
System.out.println("Case #" + t + ": " + result);
}
}
} | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
public class GoogleNumbers {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int numberOfTestCases = Integer.parseInt(s);
StringBuffer output = new StringBuffer();
for (int i = 1; i <= numberOfTestCases; i++) {
String testCase = br.readLine().trim();
String[] inputparams = testCase.split(" ");
long A, B;
A = Long.parseLong(inputparams[0]);
B = Long.parseLong(inputparams[1]);
String outputString = solveTestCase(A, B);
if (i != 1) {
output.append("\n");
}
output.append("Case #" + i + ": ");
output.append(outputString);
}
System.out.println(output);
}
private static String solveTestCase(long A, long B) {
long pairCount = 0;
int d = String.valueOf(A).length();
for (long n = A; n <= B; n++) {
String currentNumber = String.valueOf(n);
HashMap<String, String> pairedNumbers = new HashMap<String, String>();
for (int i = 1; i < d; i++) {
int subIndex = d - i;
if (currentNumber.charAt(subIndex) == '0') {
continue;
}
String newNumber = currentNumber.substring(subIndex) + currentNumber.substring(0, subIndex);
if (pairedNumbers.containsKey(newNumber)) {
continue;
}
long m = Long.valueOf(newNumber);
if (m <= n || m > B) {
continue;
}
pairedNumbers.put(newNumber, "Y");
pairCount++;
}
}
return String.valueOf(pairCount);
}
}
|
B21752 | B20274 | 0 | package Main;
import com.sun.deploy.util.ArrayUtil;
import org.apache.commons.lang3.ArrayUtils;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
/**
* Created with IntelliJ IDEA.
* User: arran
* Date: 14/04/12
* Time: 3:12 PM
* To change this template use File | Settings | File Templates.
*/
public class Round {
public StringBuilder parse(BufferedReader in) throws IOException {
StringBuilder out = new StringBuilder();
String lineCount = in.readLine();
for (int i = 1; i <= Integer.parseInt(lineCount); i++)
{
out.append("Case #"+i+": ");
System.err.println("Case #"+i+": ");
String line = in.readLine();
String[] splits = line.split(" ");
int p1 = Integer.valueOf(splits[0]);
int p2 = Integer.valueOf(splits[1]);
int r = pairRecyclable(p1, p2);
out.append(r);
// if (i < Integer.parseInt(lineCount))
out.append("\n");
}
return out;
}
public static int pairRecyclable(int i1, int i2) {
HashSet<String> hash = new HashSet<String>();
for (int i = i1; i < i2; i++)
{
String istr = String.valueOf(i);
if (istr.length() < 2) continue;
for (int p = 0; p < istr.length() ; p++)
{
String nistr = istr.substring(p,istr.length()).concat(istr.substring(0,p));
if (Integer.valueOf(nistr) < i1) continue;
if (Integer.valueOf(nistr) > i2) continue;
if (nistr.equals(istr)) continue;
String cnistr = (Integer.valueOf(nistr) > Integer.valueOf(istr)) ? istr + "," + nistr : nistr + "," + istr;
hash.add(cnistr);
}
}
return hash.size();
}
public static void main(String[] args) {
InputStreamReader converter = null;
try {
int attempt = 0;
String quest = "C";
// String size = "small-attempt";
String size = "large";
converter = new InputStreamReader(new FileInputStream("src/resource/"+quest+"-"+size+".in"));
BufferedReader in = new BufferedReader(converter);
Round r = new Round();
String str = r.parse(in).toString();
System.out.print(str);
FileOutputStream fos = new FileOutputStream(quest+"-"+size+".out");
OutputStreamWriter osw = new OutputStreamWriter(fos);
BufferedWriter bw = new BufferedWriter(osw);
bw.write(str);
bw.flush();
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
| import java.io.*;
import java.util.*;
class Recycle {
public static void main(String [] args) throws Exception{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(in.readLine());
for(int i = 0; i < T; i++){
int ans = 0;
StringTokenizer st = new StringTokenizer(in.readLine());
int A = Integer.parseInt(st.nextToken());
int B = Integer.parseInt(st.nextToken());
for(int j = A; j <= B; j++){
String s = "" + j;
HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>();
for(int k = 0; k < s.length(); k++){
String rot = s.substring(k,s.length()) + s.substring(0,k);
hm.put(Integer.parseInt(rot),0);
}
for(int k : hm.keySet()){
if(j<k&&k<=B)
ans++;
}
}
System.out.println("Case #"+(i+1)+": " + ans);
}
}
} |
A21396 | A20695 | 0 | import java.util.*;
public class Test {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int T = in.nextInt();
for(int i = 1; i<=T; i++) {
int n = in.nextInt();
int s = in.nextInt();
int p = in.nextInt();
int result = 0;
for(int j = 0; j<n; j++){
int x = canAddUp(in.nextInt(), p);
if(x == 0) {
result++;
} else if (x==1 && s > 0) {
result++;
s--;
}
}
System.out.println("Case #"+i+": "+result);
}
}
public static int canAddUp(int sum, int limit) {
boolean flag = false;
for(int i = 0; i<=sum; i++) {
for(int j = 0; i+j <= sum; j++) {
int k = sum-(i+j);
int a = Math.abs(i-j);
int b = Math.abs(i-k);
int c = Math.abs(j-k);
if(a > 2 || b > 2 || c> 2){
continue;
}
if (i>=limit || j>=limit || k>=limit) {
if(a < 2 && b < 2 && c < 2) {
return 0;
}else{
flag = true;
}
}
}
}
return (flag) ? 1 : 2;
}
}
| package quiz.number05;
import java.io.*;
import java.util.Arrays;
/**
* @author Keesun Baik
*/
public class KeesunDancingTest {
public static void main(String[] args) throws IOException {
KeesunDancingTest dancing = new KeesunDancingTest();
BufferedReader in = new BufferedReader(new FileReader("/workspace/telepathy/test/quiz/number05/B-large.in"));
String s;
int lineNum = 0;
int problemNum = 0;
String answer = "";
while ((s = in.readLine()) != null) {
if (s.isEmpty()) {
return;
}
if (lineNum == 0) {
problemNum = Integer.parseInt(s);
} else {
answer += "Case #" + lineNum + ": " + dancing.figureP(s) + "\n";
}
lineNum++;
}
in.close();
System.out.println(answer);
BufferedWriter out = new BufferedWriter(new FileWriter("/workspace/telepathy/test/quiz/number05/B-large.out"));
out.write(answer);
out.close();
}
private int figureP(String s) {
String[] inputs = s.split(" ");
int people = Integer.parseInt(inputs[0]);
int surprise = Integer.parseInt(inputs[1]);
int minScore = Integer.parseInt(inputs[2]);
String[] scoreStrings = Arrays.copyOfRange(inputs, 3, inputs.length);
int[] scores = new int[scoreStrings.length];
for (int i = 0; i < scoreStrings.length; i++) {
scores[i] = Integer.parseInt(scoreStrings[i]);
}
int cases = 0;
for (int score : scores) {
int base = score / 3;
switch (score % 3) {
case 0: {
System.out.println("0");
if (base >= minScore) {
cases++;
} else if (surprise > 0 && base > 0 && base + 1 >= minScore) {
cases++;
surprise--;
}
break;
}
case 1: {
System.out.println("1");
if (base >= minScore || base + 1 >= minScore) {
cases++;
} else if (surprise > 0 && base + 1 >= minScore) {
cases++;
surprise--;
}
break;
}
case 2: {
System.out.println("2");
if (base + 1 >= minScore || base >= minScore) {
cases++;
} else if (surprise > 0 && base + 2 >= minScore) {
cases++;
surprise--;
}
break;
}
}
}
return cases;
}
}
|
A22992 | A22568 | 0 | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package IO;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
/**
*
* @author dannocz
*/
public class InputReader {
public static Input readFile(String filename){
try {
/* Sets up a file reader to read the file passed on the command
77 line one character at a time */
FileReader input = new FileReader(filename);
/* Filter FileReader through a Buffered read to read a line at a
time */
BufferedReader bufRead = new BufferedReader(input);
String line; // String that holds current file line
int count = 0; // Line number of count
ArrayList<String> cases= new ArrayList<String>();
// Read first line
line = bufRead.readLine();
int noTestCases=Integer.parseInt(line);
count++;
// Read through file one line at time. Print line # and line
while (count<=noTestCases){
//System.out.println("Reading. "+count+": "+line);
line = bufRead.readLine();
cases.add(line);
count++;
}
bufRead.close();
return new Input(noTestCases,cases);
}catch (ArrayIndexOutOfBoundsException e){
/* If no file was passed on the command line, this expception is
generated. A message indicating how to the class should be
called is displayed */
e.printStackTrace();
}catch (IOException e){
// If another exception is generated, print a stack trace
e.printStackTrace();
}
return null;
}// end main
}
| package googlecodejam2012.qualification.dancinggooglers;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
public class DancingGooglers {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// System.out.println(hasWithoutSurprise(6, 2));
// System.out.println(hasWithoutSurprise(5, 2));
// System.out.println(hasWithoutSurprise(4, 2));
// System.out.println(hasWithoutSurprise(7, 2));
// System.out.println(hasWithoutSurprise(8, 2));
// System.out.println(hasWithoutSurprise(3, 2));
// System.out.println(hasWithoutSurprise(1, 1));
// System.out.println(hasWithoutSurprise(0, 1));
// System.out.println();
// System.out.println(hasWithSurprise(6, 2));
// System.out.println(hasWithSurprise(5, 2));
// System.out.println(hasWithSurprise(4, 2));
// System.out.println(hasWithSurprise(7, 2));
// System.out.println(hasWithSurprise(8, 2));
// System.out.println(hasWithSurprise(3, 2));
// System.out.println("Should be false: " + hasWithSurprise(2, 3));
// System.out.println("Should be false: " + hasWithSurprise(3, 3));
// System.out.println("Should be false: " + hasWithSurprise(4, 3));
// System.out.println("Should be true: " + hasWithSurprise(5, 3));
// System.out.println("Should be true: " + hasWithSurprise(6, 3));
// System.out.println("Should be true: " + hasWithSurprise(7, 3));
// System.out.println("Should be false: " + hasWithSurprise(0, 1));
String lineSep = System.getProperty("line.separator");
BufferedReader br = new BufferedReader(
args.length > 0 ? new FileReader(args[0])
: new InputStreamReader(System.in));
try {
Writer out = new BufferedWriter(args.length > 1 ? new FileWriter(args[1]): new OutputStreamWriter(System.out));
try {
int numLines = Integer.parseInt(br.readLine().trim());
for (int i = 1; i <= numLines;++i) {
String line = br.readLine();
out.write("Case #" + i + ": "+count(line) + lineSep);
}
} finally {
out.close();
}
} finally {
br.close();
}
}
private static int count(String line) {
String[] parts = line.split(" ");
int n = Integer.parseInt(parts[0]);
int s = Integer.parseInt(parts[1]);
int p = Integer.parseInt(parts[2]);
int[] sumScores = new int[parts.length - 3];
for (int i = parts.length; i -->3;) {
sumScores[i - 3] = Integer.parseInt(parts[i]);
}
return count(n, s, p, sumScores);
}
private static int count(int n, int s, int p, int[] sumScores) {
int countWithoutSurprise = 0;
int countWithPossibleSurprise = 0;
for (int sumScore : sumScores) {
if(hasWithoutSurprise(sumScore, p)) {
countWithoutSurprise++;
} else if (hasWithSurprise(sumScore, p)) {
countWithPossibleSurprise++;
}
}
return countWithoutSurprise + Math.min(s, countWithPossibleSurprise);
}
private static boolean hasWithSurprise(int sumScore, int p) {
return sumScore >= p && (sumScore + 4) /3 >= p;
}
private static boolean hasWithoutSurprise(int sumScore, int p) {
return (sumScore + 2) / 3 >= p;
}
}
|
B10899 | B12786 | 0 | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
public class ReadFile {
public static void main(String[] args) throws Exception {
String srcFile = "C:" + File.separator + "Documents and Settings"
+ File.separator + "rohit" + File.separator + "My Documents"
+ File.separator + "Downloads" + File.separator
+ "C-small-attempt1.in.txt";
String destFile = "C:" + File.separator + "Documents and Settings"
+ File.separator + "rohit" + File.separator + "My Documents"
+ File.separator + "Downloads" + File.separator
+ "C-small-attempt0.out";
File file = new File(srcFile);
List<String> readData = new ArrayList<String>();
FileReader fileInputStream = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileInputStream);
StringBuilder stringBuilder = new StringBuilder();
String line = null;
while ((line = bufferedReader.readLine()) != null) {
readData.add(line);
}
stringBuilder.append(generateOutput(readData));
File writeFile = new File(destFile);
if (!writeFile.exists()) {
writeFile.createNewFile();
}
FileWriter fileWriter = new FileWriter(writeFile);
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write(stringBuilder.toString());
bufferedWriter.close();
System.out.println("output" + stringBuilder);
}
/**
* @param number
* @return
*/
private static String generateOutput(List<String> number) {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < number.size(); i++) {
if (i == 0) {
continue;
} else {
String tempString = number.get(i);
String[] temArr = tempString.split(" ");
stringBuilder.append("Case #" + i + ": ");
stringBuilder.append(getRecNumbers(temArr[0], temArr[1]));
stringBuilder.append("\n");
}
}
if (stringBuilder.length() > 0) {
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
}
return stringBuilder.toString();
}
// /* This method accepts method for google code jam */
// private static String method(String value) {
// int intValue = Integer.valueOf(value);
// double givenExpr = 3 + Math.sqrt(5);
// double num = Math.pow(givenExpr, intValue);
// String valArr[] = (num + "").split("\\.");
// int finalVal = Integer.valueOf(valArr[0]) % 1000;
//
// return String.format("%1$03d", finalVal);
//
// }
//
// /* This method accepts method for google code jam */
// private static String method2(String value) {
// StringTokenizer st = new StringTokenizer(value, " ");
// String test[] = value.split(" ");
// StringBuffer str = new StringBuffer();
//
// for (int i = 0; i < test.length; i++) {
// // test[i]=test[test.length-i-1];
// str.append(test[test.length - i - 1]);
// str.append(" ");
// }
// str.deleteCharAt(str.length() - 1);
// String strReversedLine = "";
//
// while (st.hasMoreTokens()) {
// strReversedLine = st.nextToken() + " " + strReversedLine;
// }
//
// return str.toString();
// }
private static int getRecNumbers(String no1, String no2) {
int a = Integer.valueOf(no1);
int b = Integer.valueOf(no2);
Set<String> dupC = new HashSet<String>();
for (int i = a; i <= b; i++) {
int n = i;
List<String> value = findPerm(n);
for (String val : value) {
if (Integer.valueOf(val) <= b && Integer.valueOf(val) >= a
&& n < Integer.valueOf(val)) {
dupC.add(n + "-" + val);
}
}
}
return dupC.size();
}
private static List<String> findPerm(int num) {
String numString = String.valueOf(num);
List<String> value = new ArrayList<String>();
for (int i = 0; i < numString.length(); i++) {
String temp = charIns(numString, i);
if (!temp.equalsIgnoreCase(numString)) {
value.add(charIns(numString, i));
}
}
return value;
}
public static String charIns(String str, int j) {
String begin = str.substring(0, j);
String end = str.substring(j);
return end + begin;
}
} | import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Parser {
File instance;
Scanner sc;
public Parser(String f){
instance = new File(f);
}
public List<List<List<String>>> parse(int nbLinePerCase) throws FileNotFoundException{
sc = new Scanner(instance);
int nbCase = sc.nextInt();
List<List<List<String>>> input = new ArrayList<List<List<String>>>(nbCase);
String line;
sc.nextLine();
for(int i = 0; i < nbCase; i++){
List<List<String>> ll = new ArrayList<List<String>>(nbLinePerCase);
for(int j = 0; j < nbLinePerCase; j++){
List<String> l = new ArrayList<String>();
line = sc.nextLine();
Scanner sc2 = new Scanner(line);
while(sc2.hasNext()){
l.add(sc2.next());
}
ll.add(l);
}
input.add(ll);
}
return input;
}
}
|
B20291 | B21398 | 0 | import java.io.*;
import java.util.*;
class B
{
public static void main(String[] args)
{
try
{
BufferedReader br = new BufferedReader(new FileReader("B.in"));
PrintWriter pw = new PrintWriter(new FileWriter("B.out"));
int X = Integer.parseInt(br.readLine());
for(int i=0; i<X; i++)
{
String[] S = br.readLine().split(" ");
int A = Integer.parseInt(S[0]);
int B = Integer.parseInt(S[1]);
int R = 0;
int x = 1;
int n = 0;
while(A/x > 0) {
n++;
x *= 10;
}
for(int j=A; j<B; j++) {
Set<Integer> seen = new HashSet<Integer>();
for(int k=1; k<n; k++) {
int p1 = j % (int)Math.pow(10, k);
int p2 = (int) Math.pow(10, n-k);
int p3 = j / (int)Math.pow(10, k);
int y = p1*p2 + p3;
if(j < y && !seen.contains(y) && y <= B) {
seen.add(y);
R++;
}
}
}
pw.printf("Case #%d: %d\n", i+1, R);
pw.flush();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
|
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class RecycledNumbers {
private Scanner in;
private PrintWriter out;
public long output;
public int A;
public int B;
/**
* main method
*/
public static void main(String args[]){
new RecycledNumbers("C-large.in");
}
/**
* constructor
*/
public RecycledNumbers(String filename){
initIO(filename);
int n = in.nextInt();
// long tmStart = System.currentTimeMillis();
for(int i=1;i<=n;i++){
A = in.nextInt();
B = in.nextInt();
output = 0;
output=solve();
out.println("Case #"+i+": "+output);
}
// System.out.println(System.currentTimeMillis() - tmStart);
closeIO();
}
public long solve(){
long op=0;
Set<Integer> s = new HashSet<Integer>();
for(int i=A;i<=B;i++){
String stringI = Integer.toString(i);
s.clear();
for(int ind=stringI.length()-1;ind>0;ind--){
if(stringI.substring(ind).charAt(0)!= '0'){
String stringTemp = stringI.substring(ind) + stringI.substring(0, ind);
if(Integer.parseInt(stringTemp) > i && Integer.parseInt(stringTemp)<=B){
// System.out.println(stringI + " "+Integer.parseInt(stringTemp));
s.add(Integer.parseInt(stringTemp));
// op++;
}
}
}
op+=s.size();
}
return op;
}
/**
* Set up devices to do I/O
*/
public void initIO(String filename){
try {
in = new Scanner(new FileReader(filename));
out = new PrintWriter(new FileWriter(filename+".out"));
}catch (IOException except) {
System.err.println("File is missing!");
}
}
/**
* Free memory used for I/O
*/
public void closeIO(){
in.close();
out.close();
}
}
|
B20856 | B21892 | 0 | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Happy;
import java.io.*;
import java.math.*;
import java.lang.*;
import java.util.*;
import java.util.Arrays.*;
import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStreamReader;
//import java.io.PrintWriter;
//import java.util.StringTokenizer;
/**
*
* @author ipoqi
*/
public class Happy {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new Happy().haha();
}
public void haha() {
BufferedReader in = null;
BufferedWriter out = null;
try{
in = new BufferedReader(new FileReader("C-large.in"));
out = new BufferedWriter(new FileWriter("LLL.out"));
int T = Integer.parseInt(in.readLine());
System.out.println("T="+T);
//LinkedList<Integer> mm = new LinkedList<Integer>();
//mm.add(new LinkedList<Integer>());
//int[][] mm;
//for(int ii=0;ii<mm.length;ii++){
// mm[0][ii] = 1;
//}
for(int i=0;i<T;i++){
String[] line = in.readLine().split(" ");
int A = Integer.parseInt(line[0]);
int B = Integer.parseInt(line[1]);
//System.out.print(" A = "+A+"\n");
//System.out.print(" B = "+B+"\n");
int ans = 0;
for(int j=A;j<B;j++){
int n=j;
if(n>=10){
String N = Integer.toString(n);
int nlen = N.length();
List<Integer> oks = new ArrayList<Integer>();
for(int k=0;k<nlen-1;k++){
String M = "";
for(int kk=1;kk<=nlen;kk++){
M = M + N.charAt((k+kk)%nlen);
}
int m = Integer.parseInt(M);
//System.out.print(" N = "+N+"\n");
//System.out.print(" M = "+M+"\n");
if(m>n && m<=B) {
boolean isNewOne = true;
for(int kkk=0;kkk<oks.size();kkk++){
//System.out.print(" KKK = "+oks.get(kkk)+"\n");
if(m==oks.get(kkk)){
isNewOne = false;
}
}
if(isNewOne){
//System.out.print(" N = "+N+"\n");
//System.out.print(" M = "+M+"\n");
oks.add(m);
ans++;
}
}
}
}
}
out.write("Case #"+(i+1)+": "+ans+"\n");
System.out.print("Case #"+(i+1)+": "+ans+"\n");
}
in.close();
out.close();
}catch(Exception e){
e.printStackTrace();
try{
in.close();
out.close();
}catch(Exception e1){
e1.printStackTrace();
}
}
System.out.print("YES!\n");
}
} | import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
public class CodeJamC
{
public static void main(String args[]) throws Exception
{
Scanner in = new Scanner(new File("in.txt"));
BufferedWriter out = new BufferedWriter(new FileWriter("out.txt"));
int cases = in.nextInt();
for(int casenum = 1;casenum <= cases;casenum++)
{
int a = in.nextInt();
int b = in.nextInt();
int count = 0;
HashMap<Integer,ArrayList<Integer>> map = new HashMap<Integer,ArrayList<Integer>>();
int len = ("" + a).length();
for(int n = a;n <= b;n++)
{
int t = n;
for(int i = 0;i<len-1;i++)
{
t = (t%10)*(int)(Math.pow(10,len-1)) + t/10;
if(t > n && t <= b)
{
if(map.containsKey(n))
{
if(!map.get(n).contains(t))
{
count++;
map.get(n).add(t);
}
}
else
{
ArrayList<Integer> arr = new ArrayList<Integer>();
arr.add(t);
map.put(n,arr);
count++;
}
}
}
}
out.write("Case #" + casenum + ": " + count + "\n");
}
in.close();
out.close();
}
} |
A10996 | A10073 | 0 | import java.util.Scanner;
import java.io.*;
class dance
{
public static void main (String[] args) throws IOException
{
File inputData = new File("B-small-attempt0.in");
File outputData= new File("Boutput.txt");
Scanner scan = new Scanner( inputData );
PrintStream print= new PrintStream(outputData);
int t;
int n,s,p,pi;
t= scan.nextInt();
for(int i=1;i<=t;i++)
{
n=scan.nextInt(); s=scan.nextInt(); p=scan.nextInt();
int supTrip=0, notsupTrip=0;
for(int j=0;j<n;j++)
{
pi=scan.nextInt();
if(pi>(3*p-3))
notsupTrip++;
else if((pi>=(3*p-4))&&(pi<=(3*p-3))&&(pi>p))
supTrip++;
}
if(s<=supTrip)
notsupTrip=notsupTrip+s;
else if(s>supTrip)
notsupTrip= notsupTrip+supTrip;
print.println("Case #"+i+": "+notsupTrip);
}
}
} | import java.io.*;
import java.util.*;
/**
* @author Chris Dziemborowicz <chris@dziemborowicz.com>
* @version 2012.0414
*/
public class DancingWithTheGooglers
{
public static void main(String[] args)
throws Exception
{
// Get input files
File dir = new File("/Users/Chris/Documents/UniSVN/code-jam/dancing-with-the-googlers/data");
File[] inputFiles = dir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name)
{
return name.endsWith(".in");
}
});
// Learn score mappings
learn();
// Process each input file
for (File inputFile : inputFiles) {
System.out.printf("Processing \"%s\"...\n", inputFile.getName());
String outputPath = inputFile.getPath().replaceAll("\\.in$", ".out");
BufferedWriter writer = new BufferedWriter(new FileWriter(outputPath));
Scanner scanner = new Scanner(inputFile);
System.out.printf("Number of test cases: %s\n", scanner.nextLine());
int count = 0;
while (scanner.hasNext()) {
String line = scanner.nextLine();
String output = String.format("Case #%d: %d\n", ++count, process(line));
System.out.print(output);
writer.write(output);
}
writer.close();
System.out.println("Done.\n");
}
// Compare to reference files (if any)
for (File inputFile : inputFiles) {
System.out.printf("Verifying \"%s\"...\n", inputFile.getName());
String referencePath = inputFile.getPath().replaceAll("\\.in$", ".ref");
String outputPath = inputFile.getPath().replaceAll("\\.in$", ".out");
File referenceFile = new File(referencePath);
if (referenceFile.exists()) {
InputStream referenceStream = new FileInputStream(referencePath);
InputStream outputStream = new FileInputStream(outputPath);
boolean matched = true;
int referenceRead, outputRead;
do {
byte[] referenceBuffer = new byte[4096];
byte[] outputBuffer = new byte[4096];
referenceRead = referenceStream.read(referenceBuffer);
outputRead = outputStream.read(outputBuffer);
matched = referenceRead == outputRead
&& Arrays.equals(referenceBuffer, outputBuffer);
} while (matched && referenceRead != -1);
if (matched) {
System.out.println("Verified.\n");
} else {
System.out.println("*** NOT VERIFIED ***\n");
}
} else {
System.out.println("No reference file found.\n");
}
}
}
private static int[] highestOrdinary = new int[31];
private static int[] highestSurprising = new int[31];
public static void learn()
{
Arrays.fill(highestOrdinary, -1);
Arrays.fill(highestSurprising, -1);
for (int i = 0; i <= 10; i++) {
for (int j = i; j <= i + 2 && j <= 10; j++) {
for (int k = j; k <= i + 2 && k <= 10; k++) {
int score = i + j + k;
if (k == i + 2) {
if (k > highestSurprising[score]) {
highestSurprising[score] = k;
}
} else {
if (k > highestOrdinary[score]) {
highestOrdinary[score] = k;
}
}
}
}
}
}
public static int process(String line)
{
// Parse input
Scanner scanner = new Scanner(line);
int num = scanner.nextInt();
int numSurprising = scanner.nextInt();
int p = scanner.nextInt();
int[] scores = new int[num];
for (int i = 0; i < num; i++) {
scores[i] = scanner.nextInt();
}
// Find surprising scores
int count = 0;
for (int score : scores) {
if (highestOrdinary[score] >= p) {
count++;
} else if (numSurprising > 0 && highestSurprising[score] >= p) {
numSurprising--;
count++;
}
}
return count;
}
} |
B10155 | B10886 | 0 | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package codejam;
/**
*
* @author eblanco
*/
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import javax.swing.JFileChooser;
public class RecycledNumbers {
public static String DatosArchivo[] = new String[10000];
public static int[] convertStringArraytoIntArray(String[] sarray) throws Exception {
if (sarray != null) {
int intarray[] = new int[sarray.length];
for (int i = 0; i < sarray.length; i++) {
intarray[i] = Integer.parseInt(sarray[i]);
}
return intarray;
}
return null;
}
public static boolean CargarArchivo(String arch) throws FileNotFoundException, IOException {
FileInputStream arch1;
DataInputStream arch2;
String linea;
int i = 0;
if (arch == null) {
//frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JFileChooser fc = new JFileChooser(System.getProperty("user.dir"));
int rc = fc.showDialog(null, "Select a File");
if (rc == JFileChooser.APPROVE_OPTION) {
arch = fc.getSelectedFile().getAbsolutePath();
} else {
System.out.println("No hay nombre de archivo..Yo!");
return false;
}
}
arch1 = new FileInputStream(arch);
arch2 = new DataInputStream(arch1);
do {
linea = arch2.readLine();
DatosArchivo[i++] = linea;
/* if (linea != null) {
System.out.println(linea);
}*/
} while (linea != null);
arch1.close();
return true;
}
public static boolean GuardaArchivo(String arch, String[] Datos) throws FileNotFoundException, IOException {
FileOutputStream out1;
DataOutputStream out2;
int i;
out1 = new FileOutputStream(arch);
out2 = new DataOutputStream(out1);
for (i = 0; i < Datos.length; i++) {
if (Datos[i] != null) {
out2.writeBytes(Datos[i] + "\n");
}
}
out2.close();
return true;
}
public static void echo(Object msg) {
System.out.println(msg);
}
public static void main(String[] args) throws IOException, Exception {
String[] res = new String[10000], num = new String[2];
int i, j, k, ilong;
int ele = 1;
ArrayList al = new ArrayList();
String FName = "C-small-attempt0", istr, irev, linea;
if (CargarArchivo("C:\\eblanco\\Desa\\CodeJam\\Code Jam\\test\\" + FName + ".in")) {
for (j = 1; j <= Integer.parseInt(DatosArchivo[0]); j++) {
linea = DatosArchivo[ele++];
num = linea.split(" ");
al.clear();
// echo("A: "+num[0]+" B: "+num[1]);
for (i = Integer.parseInt(num[0]); i <= Integer.parseInt(num[1]); i++) {
istr = Integer.toString(i);
ilong = istr.length();
for (k = 1; k < ilong; k++) {
if (ilong > k) {
irev = istr.substring(istr.length() - k, istr.length()) + istr.substring(0, istr.length() - k);
//echo("caso: " + j + ": isrt: " + istr + " irev: " + irev);
if ((Integer.parseInt(irev) > Integer.parseInt(num[0])) && (Integer.parseInt(irev) > Integer.parseInt(istr)) && (Integer.parseInt(irev) <= Integer.parseInt(num[1]))) {
al.add("(" + istr + "," + irev + ")");
}
}
}
}
HashSet hs = new HashSet();
hs.addAll(al);
al.clear();
al.addAll(hs);
res[j] = "Case #" + j + ": " + al.size();
echo(res[j]);
LeerArchivo.GuardaArchivo("C:\\eblanco\\Desa\\CodeJam\\Code Jam\\test\\" + FName + ".out", res);
}
}
}
}
| package de.at.codejam.util;
import java.io.IOException;
public interface InputFileParser<CASE> {
void initialize(TaskStatus taskStatus);
TaskStatus getTaskStatus();
boolean hasNextCase();
CASE getNextCase() throws IOException;
}
|
A12460 | A11587 | 0 | /**
*
*/
package pandit.codejam;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Scanner;
/**
* @author Manu Ram Pandit
*
*/
public class DancingWithGooglersUpload {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
FileInputStream fStream = new FileInputStream(
"input.txt");
Scanner scanner = new Scanner(new BufferedInputStream(fStream));
Writer out = new OutputStreamWriter(new FileOutputStream("output.txt"));
int T = scanner.nextInt();
int N,S,P,ti;
int counter = 0;
for (int count = 1; count <= T; count++) {
N=scanner.nextInt();
S = scanner.nextInt();
counter = 0;
P = scanner.nextInt();
for(int i=1;i<=N;i++){
ti=scanner.nextInt();
if(ti>=(3*P-2)){
counter++;
continue;
}
else if(S>0){
if(P>=2 && ((ti==(3*P-3)) ||(ti==(3*P-4)))) {
S--;
counter++;
continue;
}
}
}
// System.out.println("Case #" + count + ": " + counter);
out.write("Case #" + count + ": " + counter + "\n");
}
fStream.close();
out.close();
}
}
| package ru.sidorkevich.google.jam.qualification.b;
import java.util.List;
public class Task {
int n;
int s;
int p;
List<Integer> t;
public Task(int n, int s, int p, List<Integer> t) {
this.n = n;
this.s = s;
this.p = p;
this.t = t;
}
public int getN() {
return n;
}
public int getS() {
return s;
}
public int getP() {
return p;
}
public List<Integer> getT() {
return t;
}
@Override
public String toString() {
return "Task{" +
"n=" + n +
", s=" + s +
", p=" + p +
", t=" + t +
'}';
}
}
|
B11327 | B11395 | 0 | package recycledNumbers;
public class OutputData {
private int[] Steps;
public int[] getSteps() {
return Steps;
}
public OutputData(int [] Steps){
this.Steps = Steps;
for(int i=0;i<this.Steps.length;i++){
System.out.println("Test "+(i+1)+": "+Steps[i]);
}
}
}
| /*
Author: Gaurav Gupta
Date: 14 Apr 2012
*/
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Recycled {
/**
* TODO Put here a description of what this method does.
*
* @param args
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub.
FileWriter fw = new FileWriter("Output3.txt");
PrintWriter pw = new PrintWriter(fw);
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
int sum = 0;
int A, B;
for (int i = 0; i < T; i++) {
A = sc.nextInt();
B = sc.nextInt();
sum = 0;
for (int j = A; j <= B; j++) {
int n = j;
int m;
String ns = String.valueOf(n);
String ms;
int count = 0;
int found = 0;
int rep[] = new int[ns.length()];
for (int k = 0; k < ns.length(); k++) {
ms = ns.substring(k, ns.length()) + ns.substring(0, k);
m = Integer.parseInt(ms);
if (m > n && m >= A && m <= B) {
found = 0;
for (int l = 0; l < count; l++)
if (rep[l] == m) {
found = 1;
}
if (found == 0) {
rep[count] = m;
count++;
sum++;
// System.out.println(n + " " + m);
}
}
}
}
pw.println("Case #" + (i + 1) + ": " + sum);
System.out.println("Case #" + (i + 1) + ": " + sum);
}
pw.close();
}
}
|
B12115 | B10638 | 0 | package qual;
import java.util.Scanner;
public class RecycledNumbers {
public static void main(String[] args) {
new RecycledNumbers().run();
}
private void run() {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int t = 0; t < T; t++) {
int A = sc.nextInt();
int B = sc.nextInt();
int result = solve(A, B);
System.out.printf("Case #%d: %d\n", t + 1, result);
}
}
public int solve(int A, int B) {
int result = 0;
for (int i = A; i <= B; i++) {
int dig = (int) Math.log10(A/*same as B*/) + 1;
int aa = i;
for (int d = 0; d < dig - 1; d++) {
aa = (aa % 10) * (int)Math.pow(10, dig - 1) + (aa / 10);
if (i == aa) {
break;
}
if (i < aa && aa <= B) {
// System.out.printf("(%d, %d) ", i, aa);
result++;
}
}
}
return result;
}
}
| import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class C{
public static void main(String[] args) throws FileNotFoundException
{
Scanner sc = new Scanner(new File("C.txt"));
int testCase = Integer.parseInt(sc.nextLine());
for(int Case=1; Case<=testCase; Case++)
{
int total = 0;
int st = sc.nextInt();int en = sc.nextInt();
int len = (new Integer(st)).toString().length();
for(int i=en; i>=st;i--)
{
Set s = new HashSet();
for(int j=1; j<=len-1;j++)
{
String sam = (new Integer(i).toString());
//System.out.println(i+ "Actual String:" + sam);
StringBuffer temp=new StringBuffer();
//System.out.println("temp 1:"+temp.toString());
temp.append(sam.substring(j));
//System.out.println("temp 2:"+temp.toString());
temp.append(sam.substring(0, j));
//System.out.println("temp 3:"+temp.toString());
int num = Integer.parseInt(temp.toString());
if(num>=st && num<=en && num<i){s.add(num);}
}
total += s.size();
}
System.out.println("Case #"+Case+": "+total);
}
}
} |
B11318 | B11837 | 0 | import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
int casos=1, a, b, n, m, cont;
while(t!=0){
a=sc.nextInt();
b=sc.nextInt();
if(a>b){
int aux=a;
a=b;
b=aux;
}
System.out.printf("Case #%d: ",casos++);
if(a==b){
System.out.printf("%d\n",0);
}else{
cont=0;
for(n=a;n<b;n++){
for(m=n+1;m<=b;m++){
if(isRecycled(n,m)) cont++;
}
}
System.out.printf("%d\n",cont);
}
t--;
}
}
public static boolean isRecycled(int n1, int n2){
String s1, s2, aux;
s1 = String.valueOf( n1 );
s2 = String.valueOf( n2 );
boolean r = false;
for(int i=0;i<s1.length();i++){
aux="";
aux=s1.substring(i,s1.length())+s1.substring(0,i);
// System.out.println(aux);
if(aux.equals(s2)){
r=true;
break;
}
}
return r;
}
}
| import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;
public class Numbers {
public static FileReader fr;
public static BufferedReader br;
public static FileWriter fw;
public static BufferedWriter bw;
public void read(String path) throws Exception
{
fr = new FileReader(path);
br=new BufferedReader(fr);
}
public void write(String path) throws Exception
{
}
public void execute(BufferedReader br,String path)throws Exception
{
String s;
fw =new FileWriter(path,false);
bw=new BufferedWriter(fw);
s=br.readLine();
int i1=1;
while((s=br.readLine())!=null)
{
int count =0;
String st[]=s.split("\\s");
int a=Integer.parseInt(st[0]);
int b=Integer.parseInt(st[1]);
for(int i=a;i<=b;i++)
{
int temp=i;
String abc=Integer.toString(temp);
int length=abc.length();
int index=length-1;
String tempString=abc;
while(index>0)
{
String first=tempString.substring(0, index);
String second=tempString.substring(index,length);
abc=second+first;
int newnumber=Integer.parseInt(abc);
if((newnumber<=b && newnumber>temp )&& !abc.startsWith("0") && (Integer.toString(temp).length())==abc.length())
count++;
index--;
}
}
bw.write("Case #"+ i1++ +": " +count +"\n");
}
bw.close();
fr.close();
}
public static void main(String[] args) throws Exception
{
Numbers t=new Numbers();
t.read("E:\\codejam\\Files\\A.in");
t.execute(br,"E:\\codejam\\Files\\A.out");
}
}
|
A20382 | A20695 | 0 | package dancinggooglers;
import java.io.File;
import java.util.Scanner;
public class DanceScoreCalculator {
public static void main(String[] args) {
if(args.length <= 0 || args[0] == null) {
System.out.println("You must enter a file to read");
System.out.println("Usage: blah <filename>");
System.exit(0);
}
File argFile = new File(args[0]);
try {
Scanner googleSpeakScanner = new Scanner(argFile);
String firstLine = googleSpeakScanner.nextLine();
Integer linesToScan = new Integer(firstLine);
for(int i = 1; i <= linesToScan; i++) {
String googleDancerLine = googleSpeakScanner.nextLine();
DanceScoreCase danceCase = new DanceScoreCase(googleDancerLine);
System.out.println(String.format("Case #%d: %d", i, danceCase.maxDancersThatCouldPass()));
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
| package quiz.number05;
import java.io.*;
import java.util.Arrays;
/**
* @author Keesun Baik
*/
public class KeesunDancingTest {
public static void main(String[] args) throws IOException {
KeesunDancingTest dancing = new KeesunDancingTest();
BufferedReader in = new BufferedReader(new FileReader("/workspace/telepathy/test/quiz/number05/B-large.in"));
String s;
int lineNum = 0;
int problemNum = 0;
String answer = "";
while ((s = in.readLine()) != null) {
if (s.isEmpty()) {
return;
}
if (lineNum == 0) {
problemNum = Integer.parseInt(s);
} else {
answer += "Case #" + lineNum + ": " + dancing.figureP(s) + "\n";
}
lineNum++;
}
in.close();
System.out.println(answer);
BufferedWriter out = new BufferedWriter(new FileWriter("/workspace/telepathy/test/quiz/number05/B-large.out"));
out.write(answer);
out.close();
}
private int figureP(String s) {
String[] inputs = s.split(" ");
int people = Integer.parseInt(inputs[0]);
int surprise = Integer.parseInt(inputs[1]);
int minScore = Integer.parseInt(inputs[2]);
String[] scoreStrings = Arrays.copyOfRange(inputs, 3, inputs.length);
int[] scores = new int[scoreStrings.length];
for (int i = 0; i < scoreStrings.length; i++) {
scores[i] = Integer.parseInt(scoreStrings[i]);
}
int cases = 0;
for (int score : scores) {
int base = score / 3;
switch (score % 3) {
case 0: {
System.out.println("0");
if (base >= minScore) {
cases++;
} else if (surprise > 0 && base > 0 && base + 1 >= minScore) {
cases++;
surprise--;
}
break;
}
case 1: {
System.out.println("1");
if (base >= minScore || base + 1 >= minScore) {
cases++;
} else if (surprise > 0 && base + 1 >= minScore) {
cases++;
surprise--;
}
break;
}
case 2: {
System.out.println("2");
if (base + 1 >= minScore || base >= minScore) {
cases++;
} else if (surprise > 0 && base + 2 >= minScore) {
cases++;
surprise--;
}
break;
}
}
}
return cases;
}
}
|
B10245 | B10262 | 0 | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package recyclednumbers;
import java.util.HashSet;
/**
*
* @author vandit
*/
public class RecycleNumbers {
private HashSet<String> numbers = new HashSet<String>();
private HashSet<String> initialTempNumbers = new HashSet<String>();
private HashSet<String> finalTempNumbers = new HashSet<String>();
HashSet<Pair> numberPairs = new HashSet<Pair>();
private void findRecycledNumbers(int start, int end, int places) {
for (int i = start; i <= end; i++) {
String initialNumber = Integer.toString(i);
//if (!(numbers.contains(initialNumber) || finalTempNumbers.contains(initialNumber))) {
StringBuffer tempNumber = new StringBuffer(initialNumber);
int len = tempNumber.length();
int startIndexToMove = len - places;
String tempString = tempNumber.substring(startIndexToMove);
if ((places == 1 && tempString.equals("0")) || tempString.charAt(0) == '0') {
continue;
}
tempNumber.delete(startIndexToMove, len);
String finalTempNumber = tempString + tempNumber.toString();
if (! (finalTempNumber.equals(initialNumber) || Integer.parseInt(finalTempNumber) > end || Integer.parseInt(finalTempNumber) < Integer.parseInt(initialNumber))) {
numbers.add(initialNumber);
finalTempNumbers.add(finalTempNumber);
Pair pair = new Pair(finalTempNumber,initialNumber);
numberPairs.add(pair);
}
}
}
public HashSet<Pair> findAllRecycledNumbers(int start, int end) {
int length = Integer.toString(start).length();
for (int i = 1; i < length; i++) {
findRecycledNumbers(start, end, i);
}
return numberPairs;
}
}
| package core;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public abstract class Template {
/************* TO BE IMPLEMENTED ******************************************/
public abstract void feedData(ExtendedBufferedReader iR);
public abstract StringBuffer applyMethods();
/**************************************************************************/
public void readData(File iFile){
try {
FileReader aReader = new FileReader(iFile);
ExtendedBufferedReader aBufferedReader = new ExtendedBufferedReader(aReader);
feedData(aBufferedReader);
aBufferedReader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void writeResult(File iFile,StringBuffer iResult){
System.out.println(iResult.toString());
try {
FileWriter aWriter = new FileWriter(iFile);
aWriter.write(iResult.toString());
aWriter.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void play(String[] args) {
if (args.length>1) {
File aFile = new File(args[0]);
readData(aFile);
StringBuffer result = applyMethods();
File aResultFile= new File(args[1]);
writeResult(aResultFile,result);
} else {
System.out.println("Your a bastard ! missing argument !");
}
}
}
|
B12941 | B10807 | 0 | package com.menzus.gcj._2012.qualification.c;
import com.menzus.gcj.common.InputBlockParser;
import com.menzus.gcj.common.OutputProducer;
import com.menzus.gcj.common.impl.AbstractProcessorFactory;
public class CProcessorFactory extends AbstractProcessorFactory<CInput, COutputEntry> {
public CProcessorFactory(String inputFileName) {
super(inputFileName);
}
@Override
protected InputBlockParser<CInput> createInputBlockParser() {
return new CInputBlockParser();
}
@Override
protected OutputProducer<CInput, COutputEntry> createOutputProducer() {
return new COutputProducer();
}
}
| package codejam;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class RecycledPairs {
private static String filename = "C-small-attempt0.in";
public static boolean isRecycledPair(int n, int m) {
String sn = Integer.toString(n);
String sm = Integer.toString(m);
int length = sn.length();
String shiftedString = "";
for (int i = 1; i <= length; i++) {
shiftedString = sn.substring(i, length) + sn.substring(0, i);
//System.out.println(shiftedString + " " + sn + " " + sm);
if (shiftedString.equals(sm)) return true;
}
return false;
}
public static int recycledPairs(int A, int B) {
int acc = 0;
for (int n = A, m; n < B; n++) {
m = n + 1;
for (; m <= B; m++) {
if (isRecycledPair(n, m)) acc++;
}
}
return acc;
}
public static void main(String[] args) {;
try {
BufferedReader in = new BufferedReader(new FileReader(filename));
BufferedWriter out = new BufferedWriter(new FileWriter(filename + ".out"));
String currentString = in.readLine();
int testCases = Integer.parseInt(currentString);
for (int i = 1; i <= testCases; i++) {
String[] input = in.readLine().split(" ");
int A = Integer.parseInt(input[0]);
int B = Integer.parseInt(input[1]);
int result = recycledPairs(A, B);
out.write("Case #" + i + ": " + result + '\n');
}
out.close();
in.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
|
B10858 | B12448 | 0 | package be.mokarea.gcj.common;
public abstract class TestCaseReader<T extends TestCase> {
public abstract T nextCase() throws Exception;
public abstract int getMaxCaseNumber();
}
| package qual;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
public class C {
public static int[] prepare(int m, int base, int k){
int[] res = new int[m];
for (int i = 0; i < m; i++){
int rest = k % 10;
k /= 10;
k += rest * base;
res[i] = k;
}
return res;
}
public static void main(String[] args) throws Exception{
String in_file = "q/c/s_in.txt";
String out_file = in_file.replace("_in.txt", "_out.txt");
BufferedReader in = new BufferedReader(new FileReader(in_file));
BufferedWriter out = new BufferedWriter(new FileWriter(out_file));
int n = Integer.parseInt(in.readLine());
for (int i = 1; i <= n; i++){
String[] s = in.readLine().split(" ");
int a = Integer.parseInt(s[0]);
int b = Integer.parseInt(s[1]);
int count = 0;
int base = 1;
int m = 0;
while (base * 10 <= a) {
base *= 10;
m++;
}
for (int k = a; k < b; k++){
int[] prob = prepare(m, base, k);
for (int p : prob){
if (p > k && p <= b) count++;
}
}
out.write("Case #" + i + ": " + count + "\n");
}
in.close();
out.close();
}
}
|
A12570 | A12911 | 0 | package util.graph;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Set;
public class DynDjikstra {
public static State FindShortest(Node start, Node target) {
PriorityQueue<Node> openSet = new PriorityQueue<>();
Set<Node> closedSet = new HashSet<>();
openSet.add(start);
while (!openSet.isEmpty()) {
Node current = openSet.poll();
for (Edge edge : current.edges) {
Node end = edge.target;
if (closedSet.contains(end)) {
continue;
}
State newState = edge.travel(current.last);
//if (end.equals(target)) {
//return newState;
//}
if (openSet.contains(end)) {
if (end.last.compareTo(newState)>0) {
end.last = newState;
}
} else {
openSet.add(end);
end.last = newState;
}
}
closedSet.add(current);
if (closedSet.contains(target)) {
return target.last;
}
}
return target.last;
}
}
| package com.menzus.gcj._2012.qualification.b;
import com.menzus.gcj.common.OutputEntry;
public class BOutputEntry implements OutputEntry {
private int maximumGooglersNumber;
public void setMaximumGooglersNumber(int maximumGooglersNumber) {
this.maximumGooglersNumber = maximumGooglersNumber;
}
@Override
public String formatOutput() {
return Integer.toString(maximumGooglersNumber);
}
}
|
A11277 | A13003 | 0 | package googlers;
import java.util.Scanner;
import java.util.PriorityQueue;
import java.util.Comparator;
public class Googlers {
public static void main(String[] args) {
int n,s,p,count=0,t;
Scanner sin=new Scanner(System.in);
t=Integer.parseInt(sin.nextLine());
int result[]=new int[t];
int j=0;
if(t>=1 && t<=100)
{
for (int k = 0; k < t; k++) {
count=0;
String ip = sin.nextLine();
String[]tokens=ip.split(" ");
n=Integer.parseInt(tokens[0]);
s=Integer.parseInt(tokens[1]);
p=Integer.parseInt(tokens[2]);
if( (s>=0 && s<=n) && (p>=0 && p<=10) )
{
int[] total=new int[n];
for (int i = 0; i < n; i++)
{
total[i] = Integer.parseInt(tokens[i+3]);
}
Comparator comparator=new PointComparator();
PriorityQueue pq=new PriorityQueue<Point>(1, comparator);
for (int i = 0; i < n; i++)
{
int x=total[i]/3;
int r=total[i]%3;
if(x>=p)
count++;
else if(x<(p-2))
continue;
else
{
//System.out.println("enter "+x+" "+(p-2));
if(p-x==1)
{
Point temp=new Point();
temp.q=x;
temp.r=r;
pq.add(temp);
}
else // p-x=2
{
if(r==0)
continue;
else
{
Point temp=new Point();
temp.q=x;
temp.r=r;
pq.add(temp);
}
}
}
//System.out.println("hi "+pq.size());
}
while(pq.size()!=0)
{
Point temp=(Point)pq.remove();
if(p-temp.q==1 && temp.q!=0)
{
if(temp.r>=1)
count++;
else
{
if(s!=0)
{
s--;
count++;
}
}
}
else if(p-temp.q==2)
{
if(s!=0 && (temp.q+temp.r)>=p)
{
s--;
count++;
}
}
}
//System.out.println(p);
result[j++]=count;
}
}
for (int i = 0; i < t; i++)
{
System.out.println("Case #"+(i+1)+": "+result[i]);
}
}
}
/*Point x=new Point();
x.q=8;
Point y=new Point();
y.q=6;
Point z=new Point();
z.q=7;
pq.add(x);
pq.add(y);
pq.add(z);
*/
}
class PointComparator implements Comparator<Point>
{
@Override
public int compare(Point x, Point y)
{
// Assume neither string is null. Real code should
// probably be more robust
if (x.q < y.q)
{
return 1;
}
if (x.q > y.q)
{
return -1;
}
return 0;
}
}
class Point
{
int q,r;
public int getQ() {
return q;
}
public void setQ(int q) {
this.q = q;
}
public int getR() {
return r;
}
public void setR(int r) {
this.r = r;
}
}
| package codejam;
public class Dancer extends CodeJam{
public Dancer() {
super("B-small-attempt0");
}
public static void main(String[] args) {
new Dancer().run();
}
@Override
protected String solve() {
int n = scanner.nextInt();
int s = scanner.nextInt();
int p = scanner.nextInt();
if (p == 0){
scanner.nextLine();
return n + "";
}
if (p == 1){
s = 0;
}
int sum = 3*p - 2;
int sum2 = 3*p - 4;
int count = 0;
for (int i = 0 ; i < n ; i++){
int v = scanner.nextInt();
if (v >= sum){
count++;
} else if (v >= sum2 && s-- > 0){
count++;
}
}
return count + "";
}
}
|
B11318 | B12113 | 0 | import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
int casos=1, a, b, n, m, cont;
while(t!=0){
a=sc.nextInt();
b=sc.nextInt();
if(a>b){
int aux=a;
a=b;
b=aux;
}
System.out.printf("Case #%d: ",casos++);
if(a==b){
System.out.printf("%d\n",0);
}else{
cont=0;
for(n=a;n<b;n++){
for(m=n+1;m<=b;m++){
if(isRecycled(n,m)) cont++;
}
}
System.out.printf("%d\n",cont);
}
t--;
}
}
public static boolean isRecycled(int n1, int n2){
String s1, s2, aux;
s1 = String.valueOf( n1 );
s2 = String.valueOf( n2 );
boolean r = false;
for(int i=0;i<s1.length();i++){
aux="";
aux=s1.substring(i,s1.length())+s1.substring(0,i);
// System.out.println(aux);
if(aux.equals(s2)){
r=true;
break;
}
}
return r;
}
}
| package com.renoux.gael.codejam.fwk;
import java.io.File;
import com.renoux.gael.codejam.utils.FluxUtils;
import com.renoux.gael.codejam.utils.Input;
import com.renoux.gael.codejam.utils.Output;
import com.renoux.gael.codejam.utils.Timer;
public abstract class Solver {
public void run() {
Timer.start();
if (!disableSample())
runOnce(getSampleInput(), getSampleOutput());
System.out.println(Timer.check());
Timer.start();
if (!disableSmall())
runOnce(getSmallInput(), getSmallOutput());
System.out.println(Timer.check());
Timer.start();
if (!disableLarge())
runOnce(getLargeInput(), getLargeOutput());
System.out.println(Timer.check());
}
public void runOnce(String pathIn, String pathOut) {
Input in = null;
Output out = null;
try {
in = Input.open(getFile(pathIn));
out = Output.open(getFile(pathOut));
int countCases = Integer.parseInt(in.readLine());
for (int k = 1; k <= countCases; k++) {
out.write("Case #", k, ": ");
solveCase(in, out);
}
} catch (RuntimeException e) {
e.printStackTrace();
} finally {
FluxUtils.closeCloseables(in, out);
}
}
private File getFile(String path) {
return new File(path);
}
protected abstract void solveCase(Input in, Output out);
private String getFullPath(boolean input, String type) {
if (input)
return "D:\\Downloads\\CodeJam\\" + getProblemName() + "\\"
+ getProblemName() + "_input_" + type + ".txt";
else
return "D:\\Downloads\\CodeJam\\" + getProblemName() + "\\"
+ getProblemName() + "_output_" + type + ".txt";
}
protected String getSampleInput() {
return getFullPath(true, "sample");
}
protected String getSmallInput() {
return getFullPath(true, "small");
}
protected String getLargeInput() {
return getFullPath(true, "large");
}
protected String getSampleOutput() {
return getFullPath(false, "sample");
}
protected String getSmallOutput() {
return getFullPath(false, "small");
}
protected String getLargeOutput() {
return getFullPath(false, "large");
}
protected boolean disableSample() {
return disable()[0];
}
protected boolean disableSmall() {
return disable()[1];
}
protected boolean disableLarge() {
return disable()[2];
}
protected boolean[] disable() {
return new boolean[] { false, false, false };
}
protected abstract String getProblemName();
}
|
End of preview. Expand
in Dataset Viewer.
No dataset card yet
New: Create and edit this dataset card directly on the website!
Contribute a Dataset Card- Downloads last month
- 11