miércoles, 1 de junio de 2011

Mispelling

Misspelling is an art form that students seem to excel at. Write a program that removes the nth character from an input string.
Input

The first line of input contains a single integer N, (1 ≤ N ≤ 1000) which is the number of datasets that follow.

Each dataset consists of a single line of input containing M, a space, and a single word made up of uppercase letters only. M will be less than or equal to the length of the word. The length of the word is guaranteed to be less than or equal to 80.
Output

For each dataset, you should generate one line of output with the following values: The dataset number as a decimal integer (start counting at one), a space, and the misspelled word. The misspelled word is the input word with the indicated character deleted. 


Example
Input:
4
4 MISSPELL
1 PROGRAMMING
7 CONTEST
3 BALLOON

Output:
1 MISPELL
2 ROGRAMMING
3 CONTES
4 BALOON




https://www.spoj.pl/problems/GNY07A/




public class Mispelling
{
   public static void main( String args[] ) throws Exception
   {  
      char bufferSalida[] = new char[ 8000 ];
      int tamanio = 0;
      int car, numCaso = 0, posEliminar, temp;
      int numCasos = sig();
  
      for( int i = 0; i < numCasos; i ++ )
      {
         posEliminar = sig();
   
         // Anadimos el numero de caso al inicio
         numCaso ++;
 
         /*
         * Hallamos la representacion en caracteres para el valor
         * de numCaso
         */
         if( numCaso < 10 )
            bufferSalida[ tamanio ++ ] = (char)( numCaso + 48 );
   
         else if( numCaso < 100 )
         {
            bufferSalida[ tamanio ++ ] = (char)( numCaso/10 + 48 );
            bufferSalida[ tamanio ++ ] = (char)( numCaso%10 + 48 );
         }
         else if( numCaso < 1000 )
         {
            bufferSalida[ tamanio ++ ] = (char)( numCaso/100 + 48 );
            temp = numCaso % 100;
            bufferSalida[ tamanio ++ ] = (char)( temp/10 + 48 );
            bufferSalida[ tamanio ++ ] = (char)( temp%10 + 48 );
         }
   
         // Anadimos el espacio en blanco
         bufferSalida[ tamanio ++ ] = ' ';
   
         // Guardamos los caracteres menos el de posicion posEliminar
         for( int j = 1; j < posEliminar; j ++ )
         bufferSalida[ tamanio ++ ] = (char)System.in.read();
   
         // Nos saltamos el caracter de posicion posEliminar
         System.in.read();
   
         // Guardamos los siguientes caracteres hasta encontrar el fin de linea
         car = System.in.read();
   
         while( car != 10 )
         {
            bufferSalida[ tamanio ++ ] = (char)car;
            car = System.in.read();
         }
   
         // Guardamos el caracter de fin de linea
         bufferSalida[ tamanio ++ ] = (char)car;
      }
  
      // Mostramos el buffer de salida
      System.out.print( new String( bufferSalida, 0, tamanio ) );
   }
 
   public static int sig() throws Exception
   {
      int car = System.in.read();
      int val = 0;
  
      while( car > 47 && car < 58 )
      {
         val = 10 * val + ( car - 48 );
         car = System.in.read();
      }
      return val;
   }
}

No hay comentarios:

Publicar un comentario