1.


/**
* Angewandte Mathematik, SS11
* Problem: 392 Polynomial Showdown
* Link: http://uva.onlinejudge.org/external/3/392.html
*
* @author Wolff, Marco
* @author Weber, Christian
* @author Waldleitner, Christoph
* @version 1.0, 05/11/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 2,288
*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class Main {
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer coeffs = new StringTokenizer("");
String input = "", output = "";
int token = 0;
while(true) {
try {
input = br.readLine();
if(input == null)
break;
coeffs = new StringTokenizer(input);
}
catch(IOException e) {
e.getMessage();
}
if(!coeffs.hasMoreTokens())
break;
while(coeffs.hasMoreTokens()) {
while(coeffs.countTokens() > 2) {
token = Integer.parseInt(coeffs.nextToken());
if(Math.abs(token) > 1000)
break;
if(token > 0 && output != "")
output += " +";
if(token < 0 && output == "") {
if(token != -1)
output += "-" + Math.abs(token) + "x^" + coeffs.countTokens();
else
output += "-x^" + coeffs.countTokens();
}
else if(token > 0 && output == "") {
if(token != 1)
output += token + "x^" + coeffs.countTokens();
else
output += "x^" + coeffs.countTokens();
}
else if(token < 0 && coeffs.countTokens() <= 7) {
if(token != -1)
output += " - " + Math.abs(token) + "x^" + coeffs.countTokens();
else
output += " - x^" + coeffs.countTokens();
}
else if (token > 0 && coeffs.countTokens() <= 7) {
if(token != 1)
output += " " + token + "x^" + coeffs.countTokens();
else
output += " x^" + coeffs.countTokens();
}
}
token = Integer.parseInt(coeffs.nextToken());
if(token > 0 && output != "")
output += " +";
if(token < 0 && coeffs.countTokens() > 0) {
if(token != -1) {
if(output != "")
output += " - " + Math.abs(token) + "x";
else
output += "-" + Math.abs(token) + "x";
}
else {
if(output != "")
output += " - x";
else
output += "-x";
}
}
else if(token > 0 && coeffs.countTokens() > 0) {
if(token != 1) {
if(output != "")
output += " " + token + "x";
else
output += token + "x";
}
else {
if(output != "")
output += " x";
else
output += "x";
}
}
else if(token < 0 && coeffs.countTokens() == 0) {
if(output != "")
output += " - " + Math.abs(token);
else
output += "-" + Math.abs(token);
}
else if(token > 0 && coeffs.countTokens() == 0) {
if(output != "")
output += " " + token;
else
output += token;
}
else if((token == 0 && coeffs.countTokens() == 0) && output == "")
output += token;
}
output = output.trim();
System.out.println(output);
output = "";
}
}
}

2.

/**
* Angewandte Mathematik, SS11
* Problem: 392 - Polynomial Showdown
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=328
*
* @author Markus Schöllner
* @author Andreas Maier
* @version 1.0, 03/29/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 2.584
*/
import java.util.*;


public class Main {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

String output="";
double input;

while(scanner.hasNextInt()){
output="";
for(int c = 0; c <=6;c++){
input = scanner.nextInt();
switch((int)Math.signum(input)){
case 0:
break;
case -1:
input = Math.abs(input);
if(output == ""){
if(input==1) output = output+"-"+"x^"+(8-c);
else output = output+"-"+(int)input+"x^"+(8-c);
}
else {
if(input==1) output = output + " - "+"x^"+(8-c);
else output = output+" - "+(int)input+"x^"+(8-c);
}
break;
case 1:
if(output == ""){
if(input==1) output = output+"x^"+(8-c);
else output = output+(int)input+"x^"+(8-c);
}
else {
if(input==1) output = output + " + "+"x^"+(8-c);
else output = output + " + "+(int)input+"x^"+(8-c);
}
break;
}
}
input = scanner.nextInt();
switch((int)Math.signum(input)){
case 0:
break;
case -1:
input = Math.abs(input);
if(output == ""){
if(input==1) output = output+"-"+"x";
else output = output+"-"+(int)input+"x";
}
else {
if(input==1) output = output + " - "+"x";
else output = output+" - "+(int)input+"x";
}
break;
case 1:
if(output == ""){
if(input==1) output = output+"x";
else output = output+(int)input+"x";
}
else {
if(input==1) output = output + " + "+"x";
else output = output + " + "+(int)input+"x";
}
break;
}

input = scanner.nextInt();
switch((int)Math.signum(input)){
case 0:
if(output=="") output="0";
break;
case 1:
if(output=="") output =""+(int)input;
else output = output + " + "+(int)input;
break;
case -1:
if(output=="") output ="-"+(-1*(int)input);
else output = output +" - "+(-1*(int)input);
break;

}
System.out.println(output);
}
}
}

3.

/**
* Angewandte Mathematik, SS11
* Problem: 392 - Polynomial Showdown
* Link: http://uva.onlinejudge.org/external/3/392.html
*
* @author Fabian Trampusch
* @author Robert Schwarz
* @version 1.0, 15/05/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 1.596
*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

while (true) {
int[] input = null;

try {
input = readIntArr(br.readLine());
} catch (Exception e) {
System.exit(0);
}

StringBuilder sb = new StringBuilder();
int n = input.length - 1;
boolean first = true;

for (int i = 0; i < input.length; i++) {
// First input not zero
if (first && input[i] != 0) {

if (input[i] < 0)
sb.append("-");

// dont show a 1 - only if it is the last digit.
if (Math.abs(input[i]) != 1 || input.length - 1 == i)
sb.append(Math.abs(input[i]));

// First input is last input
if (n > 0) {
sb.append("x");
if (n > 1) {
sb.append("^" + n);
}
}

first = false;
} else if (input[i] != 0) {
if (input[i] < 0)
sb.append(" - ");
else
sb.append(" + ");

if (Math.abs(input[i]) != 1 || n == 0)
sb.append(Math.abs(input[i]));

if (n > 0) {
sb.append("x");
if (n > 1) {
sb.append("^" + n);
}
}
}

n--;
}

if (sb.length() == 0)
sb.append(0);

System.out.println(sb.toString());
}
}

public static int[] readIntArr(String line) throws Exception {
StringTokenizer st = new StringTokenizer(line);

if(st.countTokens() != 9)
System.exit(0);

int countElements = st.countTokens();
int[] readInts = new int[countElements];

for (int i = 0; i < countElements; i++) {
readInts[i] = Integer.parseInt(st.nextToken());
}

return readInts;
}
}