// Codeforces Round #157 (Div. 2): C - Little Elephant and Bits
import java.io.*;
import java.math.*;
import java.util.*;
//codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
public static void main(String[] args) throws IOException {
// helpers for input/output
boolean LOCAL_TEST = false;
// LOCAL_TEST = true;// comment it before submitting
out = System.out;
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin2.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}
solve();
}
private static void solve() throws IOException
{
String s = in.nextString();
char[] c = s.toCharArray();
StringBuilder ans = new StringBuilder("" + String.valueOf(c[0]));
for (int i = 1; i < c.length - 1; i++) {
if (c[i] == '1')
{
ans.append(String.valueOf(c[i]));
}
else
{
for (int j = i + 1; j < c.length; j++) {
ans.append(String.valueOf(c[j]));
}
break;
}
}
out.println(ans.toString());
}
// =====================================
static class MyScanner {
Scanner inp = null;
public MyScanner() throws IOException
{
inp = new Scanner(System.in);
}
public MyScanner(String inputFile) throws IOException {
inp = new Scanner(new FileInputStream(inputFile));
}
public int nextInt() throws IOException {
return inp.nextInt();
}
public long nextLong() throws IOException {
return inp.nextLong();
}
public double nextDouble() throws IOException {
return inp.nextDouble();
}
public String nextString() throws IOException {
return inp.next();
}
}
}
Some solution examples of problems in topcoder, codeeval, google code jam, interviewstreet, onlinejudge-uva, codeforces, projecteuler, etc
Thursday, January 31, 2013
Codeforces Round #157 (Div. 2): B - Little Elephant and Magic Square
// Codeforces Round #157 (Div. 2): B - Little Elephant and Magic Square
import java.io.*;
import java.math.*;
import java.util.*;
//codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
public static void main(String[] args) throws IOException {
// helpers for input/output
boolean LOCAL_TEST = false;
// LOCAL_TEST = true;// comment it before submitting
out = System.out;
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin2.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}
solve();
}
private static void solve() throws IOException
{
Integer[] x = new Integer[9];
for (int i = 0; i < 9; i++) {
x[i] = in.nextInt();
}
int sum2 = x[2] + x[6];
for (int x0 = 1; x0 <= 100000; x0++)
{
x[0] = x0;
x[8] = sum2 - x[0];
int sum3 = x[0] + x[3] + x[6];
if (x[6] + x[7] + x[8] == sum3)
{
x[4] = sum3 - x[0] - x[8];
if (x[8] > 0 && x[4] > 0)
break;
}
}
int k = 0;
out.println(x[k++] + " " + x[k++] + " " + x[k++]);
out.println(x[k++] + " " + x[k++] + " " + x[k++]);
out.println(x[k++] + " " + x[k++] + " " + x[k++]);
}
static class MyScanner {
StreamTokenizer in;
public MyScanner() throws IOException
{
Reader r = new BufferedReader(new InputStreamReader(System.in));
in = new StreamTokenizer(r);
}
public MyScanner(String inputFile) throws IOException {
Reader r;
r = new BufferedReader(new FileReader(inputFile));
in = new StreamTokenizer(r);
}
public int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
public long nextLong() throws IOException {
in.nextToken();
return (long) in.nval;
}
public double nextDouble() throws IOException {
in.nextToken();
return in.nval;
}
public String nextString() throws IOException {
in.nextToken();
if (in.ttype == StreamTokenizer.TT_WORD)
return in.sval;
else if (in.ttype == StreamTokenizer.TT_NUMBER)
return String.valueOf(in.nval);
else
return null;
}
}
}
import java.io.*;
import java.math.*;
import java.util.*;
//codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
public static void main(String[] args) throws IOException {
// helpers for input/output
boolean LOCAL_TEST = false;
// LOCAL_TEST = true;// comment it before submitting
out = System.out;
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin2.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}
solve();
}
private static void solve() throws IOException
{
Integer[] x = new Integer[9];
for (int i = 0; i < 9; i++) {
x[i] = in.nextInt();
}
int sum2 = x[2] + x[6];
for (int x0 = 1; x0 <= 100000; x0++)
{
x[0] = x0;
x[8] = sum2 - x[0];
int sum3 = x[0] + x[3] + x[6];
if (x[6] + x[7] + x[8] == sum3)
{
x[4] = sum3 - x[0] - x[8];
if (x[8] > 0 && x[4] > 0)
break;
}
}
int k = 0;
out.println(x[k++] + " " + x[k++] + " " + x[k++]);
out.println(x[k++] + " " + x[k++] + " " + x[k++]);
out.println(x[k++] + " " + x[k++] + " " + x[k++]);
}
static class MyScanner {
StreamTokenizer in;
public MyScanner() throws IOException
{
Reader r = new BufferedReader(new InputStreamReader(System.in));
in = new StreamTokenizer(r);
}
public MyScanner(String inputFile) throws IOException {
Reader r;
r = new BufferedReader(new FileReader(inputFile));
in = new StreamTokenizer(r);
}
public int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
public long nextLong() throws IOException {
in.nextToken();
return (long) in.nval;
}
public double nextDouble() throws IOException {
in.nextToken();
return in.nval;
}
public String nextString() throws IOException {
in.nextToken();
if (in.ttype == StreamTokenizer.TT_WORD)
return in.sval;
else if (in.ttype == StreamTokenizer.TT_NUMBER)
return String.valueOf(in.nval);
else
return null;
}
}
}
Codeforces Round #157 (Div. 2): A - Little Elephant and Chess
// Codeforces Round #157 (Div. 2): A - Little Elephant and Chess
import java.io.*;
import java.math.*;
import java.util.*;
//codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
public static void main(String[] args) throws IOException {
// helpers for input/output
boolean LOCAL_TEST = false;
// LOCAL_TEST = true;// comment it before submitting
out = System.out;
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin2.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}
solve();
}
private static void solve() throws IOException
{
boolean possible = true;
for (int i = 0; i < 8; i++) {
String s = in.nextString();
if (!(s.equals("WBWBWBWB") || s.equals("BWBWBWBW")))
possible = false;
}
if (possible)
out.println("YES");
else
out.println("NO");
}
static class MyScanner {
StreamTokenizer in;
public MyScanner() throws IOException
{
Reader r = new BufferedReader(new InputStreamReader(System.in));
in = new StreamTokenizer(r);
}
public MyScanner(String inputFile) throws IOException {
Reader r;
r = new BufferedReader(new FileReader(inputFile));
in = new StreamTokenizer(r);
}
public int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
public long nextLong() throws IOException {
in.nextToken();
return (long) in.nval;
}
public double nextDouble() throws IOException {
in.nextToken();
return in.nval;
}
public String nextString() throws IOException {
in.nextToken();
if (in.ttype == StreamTokenizer.TT_WORD)
return in.sval;
else if (in.ttype == StreamTokenizer.TT_NUMBER)
return String.valueOf(in.nval);
else
return null;
}
}
}
import java.io.*;
import java.math.*;
import java.util.*;
//codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
public static void main(String[] args) throws IOException {
// helpers for input/output
boolean LOCAL_TEST = false;
// LOCAL_TEST = true;// comment it before submitting
out = System.out;
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin2.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}
solve();
}
private static void solve() throws IOException
{
boolean possible = true;
for (int i = 0; i < 8; i++) {
String s = in.nextString();
if (!(s.equals("WBWBWBWB") || s.equals("BWBWBWBW")))
possible = false;
}
if (possible)
out.println("YES");
else
out.println("NO");
}
static class MyScanner {
StreamTokenizer in;
public MyScanner() throws IOException
{
Reader r = new BufferedReader(new InputStreamReader(System.in));
in = new StreamTokenizer(r);
}
public MyScanner(String inputFile) throws IOException {
Reader r;
r = new BufferedReader(new FileReader(inputFile));
in = new StreamTokenizer(r);
}
public int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
public long nextLong() throws IOException {
in.nextToken();
return (long) in.nval;
}
public double nextDouble() throws IOException {
in.nextToken();
return in.nval;
}
public String nextString() throws IOException {
in.nextToken();
if (in.ttype == StreamTokenizer.TT_WORD)
return in.sval;
else if (in.ttype == StreamTokenizer.TT_NUMBER)
return String.valueOf(in.nval);
else
return null;
}
}
}
Tuesday, January 22, 2013
Codeforces Round #156 (Div. 2): B - Code Parsing
// Codeforces Round #156 (Div. 2): B - Code Parsing
import java.io.*;
import java.math.*;
import java.util.*;
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
public static void main(String[] args) throws IOException {
// helpers for input/output
boolean LOCAL_TEST = false;
// LOCAL_TEST = true;// comment it before submitting
out = System.out;
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin2.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}
solve();
}
private static void solve() throws IOException
{
// int k = in.nextInt();
String s = in.nextString();
LinkedList<Character> ss = new LinkedList<Character>();
ListIterator<Character> it = ss.listIterator();
for (int i = 0; i < s.length(); i++) {
it.add(s.charAt(i));
}
while (it.hasPrevious())
it.previous();
while (true) {
Character cur = it.next();
if (!it.hasNext())
break;
Character next = it.next();
if (cur != next) {
it.previous();
it.remove();
it.previous();
it.remove();
}
if (it.hasPrevious())
it.previous();
}
while (it.hasPrevious())
it.previous();
StringBuffer sb = new StringBuffer("");
while (it.hasNext())
{
Character c = it.next();
sb.append(c);
}
out.println(sb);
}
static class MyScanner {
StreamTokenizer in;
public MyScanner() throws IOException
{
Reader r = new BufferedReader(new InputStreamReader(System.in));
in = new StreamTokenizer(r);
}
public MyScanner(String inputFile) throws IOException {
Reader r;
r = new BufferedReader(new FileReader(inputFile));
in = new StreamTokenizer(r);
}
public int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
public long nextLong() throws IOException {
in.nextToken();
return (long) in.nval;
}
public double nextDouble() throws IOException {
in.nextToken();
return in.nval;
}
public String nextString() throws IOException {
in.nextToken();
if (in.ttype == StreamTokenizer.TT_WORD)
return in.sval;
else if (in.ttype == StreamTokenizer.TT_NUMBER)
return String.valueOf(in.nval);
else
return null;
}
}
}
import java.io.*;
import java.math.*;
import java.util.*;
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
public static void main(String[] args) throws IOException {
// helpers for input/output
boolean LOCAL_TEST = false;
// LOCAL_TEST = true;// comment it before submitting
out = System.out;
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin2.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}
solve();
}
private static void solve() throws IOException
{
// int k = in.nextInt();
String s = in.nextString();
LinkedList<Character> ss = new LinkedList<Character>();
ListIterator<Character> it = ss.listIterator();
for (int i = 0; i < s.length(); i++) {
it.add(s.charAt(i));
}
while (it.hasPrevious())
it.previous();
while (true) {
Character cur = it.next();
if (!it.hasNext())
break;
Character next = it.next();
if (cur != next) {
it.previous();
it.remove();
it.previous();
it.remove();
}
if (it.hasPrevious())
it.previous();
}
while (it.hasPrevious())
it.previous();
StringBuffer sb = new StringBuffer("");
while (it.hasNext())
{
Character c = it.next();
sb.append(c);
}
out.println(sb);
}
static class MyScanner {
StreamTokenizer in;
public MyScanner() throws IOException
{
Reader r = new BufferedReader(new InputStreamReader(System.in));
in = new StreamTokenizer(r);
}
public MyScanner(String inputFile) throws IOException {
Reader r;
r = new BufferedReader(new FileReader(inputFile));
in = new StreamTokenizer(r);
}
public int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
public long nextLong() throws IOException {
in.nextToken();
return (long) in.nval;
}
public double nextDouble() throws IOException {
in.nextToken();
return in.nval;
}
public String nextString() throws IOException {
in.nextToken();
if (in.ttype == StreamTokenizer.TT_WORD)
return in.sval;
else if (in.ttype == StreamTokenizer.TT_NUMBER)
return String.valueOf(in.nval);
else
return null;
}
}
}
Saturday, January 5, 2013
Codeforces Round #156 (Div. 2): A - Greg's Workout
// Codeforces Round #156 (Div. 2): A - Greg's Workout
import java.io.*;
import java.math.*;
import java.util.*;
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
public static void main(String[] args) throws IOException {
// helpers for input/output
boolean LOCAL_TEST = false;
// LOCAL_TEST = true;// comment it before submitting
out = System.out;
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin2.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}
solve();
}
private static void solve() throws IOException
{
int N = in.nextInt();
int[] sum = new int[3];
sum[0] = sum[1] = sum[2] = 0;
for (int i = 0; i < N; i++) {
int a = in.nextInt();
sum[i % 3] += a;
}
int max = Math.max(sum[0], Math.max(sum[1], sum[2]));
if (max == sum[0])
out.println("chest");
else if (max == sum[1])
out.println("biceps");
else
out.println("back");
}
static class MyScanner {
StreamTokenizer in;
public MyScanner() throws IOException
{
Reader r = new BufferedReader(new InputStreamReader(System.in));
in = new StreamTokenizer(r);
}
public MyScanner(String inputFile) throws IOException {
Reader r;
r = new BufferedReader(new FileReader(inputFile));
in = new StreamTokenizer(r);
}
public int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
public long nextLong() throws IOException {
in.nextToken();
return (long) in.nval;
}
public double nextDouble() throws IOException {
in.nextToken();
return in.nval;
}
public String nextString() throws IOException {
in.nextToken();
return in.sval;
}
}
}
import java.io.*;
import java.math.*;
import java.util.*;
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
public static void main(String[] args) throws IOException {
// helpers for input/output
boolean LOCAL_TEST = false;
// LOCAL_TEST = true;// comment it before submitting
out = System.out;
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin2.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}
solve();
}
private static void solve() throws IOException
{
int N = in.nextInt();
int[] sum = new int[3];
sum[0] = sum[1] = sum[2] = 0;
for (int i = 0; i < N; i++) {
int a = in.nextInt();
sum[i % 3] += a;
}
int max = Math.max(sum[0], Math.max(sum[1], sum[2]));
if (max == sum[0])
out.println("chest");
else if (max == sum[1])
out.println("biceps");
else
out.println("back");
}
static class MyScanner {
StreamTokenizer in;
public MyScanner() throws IOException
{
Reader r = new BufferedReader(new InputStreamReader(System.in));
in = new StreamTokenizer(r);
}
public MyScanner(String inputFile) throws IOException {
Reader r;
r = new BufferedReader(new FileReader(inputFile));
in = new StreamTokenizer(r);
}
public int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
public long nextLong() throws IOException {
in.nextToken();
return (long) in.nval;
}
public double nextDouble() throws IOException {
in.nextToken();
return in.nval;
}
public String nextString() throws IOException {
in.nextToken();
return in.sval;
}
}
}
Subscribe to:
Posts (Atom)