Hi WA !!!!!
Posted: Thu Mar 17, 2005 6:21 pm
I'm trying with yours tests and all seems to be ok! I don't know where is my problem.
Thanks!
Thanks!
Code: Select all
1999999999999999998
470
59822
9000
6692 < ---- ????
10000
Code: Select all
import java.util.StringTokenizer;
import java.util.Vector;
/**@author Eric
* Created on 2005-6-8
*/
class Main {
public static void main(String[] args) {
try{
String line = Main.readLine();
int c = Integer.parseInt(line.trim());
int digit;
short a, b, d;
StringTokenizer st;
Vector v = new Vector();
for(int i=0 ; i<c ; i++){
line = Main.readLine();
digit = Integer.parseInt(line.trim());
for(int j=0 ; j<digit ; j++){
line = Main.readLine();
st = new StringTokenizer(line.trim());
a = Short.parseShort(st.nextToken().trim());
b = Short.parseShort(st.nextToken().trim());
while(b>0){
a++;
b--;
}
if (a > 9){
a -= 10;
v.addElement(""+a);
int k = v.size()-2;
while(Integer.parseInt((String)v.elementAt(k))+1>9){ v.removeElementAt(k);
v.insertElementAt(""+0,k);
k--;
}
d = Short.parseShort((String)v.elementAt(k));
v.removeElementAt(k);
v.insertElementAt(""+(d+1),k);
for (k=0 ; k<v.size()-1 ; k++){
System.out.print((String)v.elementAt(0));
v.removeElementAt(0);
}
}else{
v.addElement(""+a);
if(a<9){
for (int k=0 ; k<v.size()-1 ; k++){
System.out.print((String)v.elementAt(0));
v.removeElementAt(0);
}
}
}
}
for (int j=0 ; j<v.size() ; j++){
System.out.print((String)v.elementAt(0));
v.removeElementAt(0);
}
if(i!=c-1){
System.out.println("\n");
}
}
}catch(Exception e){
System.err.println(e.getMessage());
}
}
static String readLine(){return token( "\n\r" );}
/* read token from stdIn with standard delims */
static String token( ){return token( " \n\r\t" );}
/* read token from stdIn with custom delims */
/* returns null for end of file or any exceptions */
static String token( String delim ){
char c = delim.charAt(0);
StringBuffer s = new StringBuffer("");
try{
while( delim.indexOf( (int) c ) != -1 && c != 65535 )
c = (char) System.in.read();
while( delim.indexOf( (int) c ) == -1 && c != 65535 ){
s.append( (char) c );
c = (char) System.in.read();
}
}catch( Exception e ){ return (null); }
if( s.toString().equals("") ) return null;
return s.toString();
}
}
Code: Select all
import java.util.StringTokenizer;
/**@author Eric
* Created on 2005-6-9
*/
class Main {
public static void main(String[] args) {
short [] res;
String line = Main.readLine();
int c = Integer.parseInt(line.trim());
short a, b, base, over, d;
int digit;
StringTokenizer st;
for(int i=0 ; i<c ; i++){
res = new short [1000000];
line = Main.readLine();
digit = Integer.parseInt(line.trim());
for(int j=0 ; j<digit ; j++){
line = Main.readLine();
st = new StringTokenizer(line.trim());
a = Short.parseShort(st.nextToken().trim());
b = Short.parseShort(st.nextToken().trim());
while(b>0){
a++;
b--;
}
res[j] = a;
}
for(int j=digit-1 ; j>=0 ; j--){
if (res[j]>=10){
res[j]-=10;
res[j-1]+=1;
}
}
for (int j=0 ; j<digit ; j++){
System.out.print(res[j]);
}
if (i != c-1){
System.out.println("\n");
}
}
}
static String readLine(){return token( "\n\r" );}
/* read token from stdIn with standard delims */
static String token( ){return token( " \n\r\t" );}
/* read token from stdIn with custom delims */
/* returns null for end of file or any exceptions */
static String token( String delim ){
char c = delim.charAt(0);
StringBuffer s = new StringBuffer("");
try{
while( delim.indexOf( (int) c ) != -1 && c != 65535 )
c = (char) System.in.read();
while( delim.indexOf( (int) c ) == -1 && c != 65535 ){
s.append( (char) c );
c = (char) System.in.read();
}
}catch( Exception e ){ return (null); }
if( s.toString().equals("") ) return null;
return s.toString();
}
}
Code: Select all
public static String readLn (int maxLg){
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
try{
while (lg < maxLg){
car = System.in.read();
if ((car < 0) || (car == '\n')) break;
lin [lg++] += car;
}
}catch (java.io.IOException e){
return (null);
}
if ((car < 0) && (lg == 0)) return (null); // eof
return (new String (lin, 0, lg));
}
Code: Select all
1
1
0 0