Java > Coucou

TitreCoucou
Postée le11-10-2009
Affichée555
Mini-lien
Description

=(

EtatInconnu. Inconnu.
Code d'insertion
Options
Afficher les numéros de lignes  Mettre la source en plein ecran  Selectionner la source  Partager sur Facebook 
Téléchargement Telecharger en format txt  Telecharger en format pdf  Telecharger en format java
Plein ecran
import java.util.ArrayList;
import java.util.Scanner;


class Main
{
  private static String traduction(int N, int M, String[] traduction, String s)
  {
         String chaine = "" ;
        for(int i = 0 ; i < N ; i += 3)
        {
                int a = 0 ;
                int b = 0 ;
                for(int j = 0 ; j < 3 ; j++)
                {
                    if(s.charAt(i+j) == 'C')
                          a = 1 ;
                    else if(s.charAt(i+j) == 'T')
                          a = 2 ;
                    else if(s.charAt(i+j) == 'G')
                          a = 3 ;
                    else
                        a = 0 ;
                   
                     b += a * (int)java.lang.Math.pow(4, 2-j) ;
                }
               
               
                chaine += traduction[b] + " " ;
               
               
        }
       
        return chaine ;
         

     
  }

  public static void main(String args[]) throws java.io.IOException
  {
    Scanner scanner = new Scanner(System.in);
    int N;
    int M;
    String adn;

    N = scanner.nextInt();
    scanner.nextLine();

    M = scanner.nextInt();
    scanner.nextLine();
   
    int nombre = 0 ;
   
    String[][] table_traduction = new String[64][1] ;
    String[] traduction = new String[64] ;
   
    for (int i = 0; i < M; ++i)
    {
       
      int a = 0 ;
      int b = 0 ;
      int c = 0 ;
       
      table_traduction[i] = scanner.nextLine().split(" ");
     
      if(table_traduction[i][0].charAt(0) == 'C')
          a = 1 ;
      else if(table_traduction[i][0].charAt(0) == 'T')
          a = 2 ;
      else if(table_traduction[i][0].charAt(0) == 'G')
          a = 3 ;
      else
          a = 0 ;
     
      if(table_traduction[i][0].charAt(1) == 'C')
          b = 1 ;
      else if(table_traduction[i][0].charAt(1) == 'T')
          b = 2 ;
      else if(table_traduction[i][0].charAt(1) == 'G')
          b = 3 ;
      else b = 0 ;
     
      if(table_traduction[i][0].charAt(2) == 'C')
          c = 1 ;
      else if(table_traduction[i][0].charAt(2) =='T')
          c = 2 ;
      else if(table_traduction[i][0].charAt(2) == 'G')
          c = 3 ;
      else c = 0 ;
     
      nombre = a * ((int)java.lang.Math.pow(4,2)) + b * ((int)java.lang.Math.pow(4, 1)) + c * ((int)java.lang.Math.pow(4,0)) ;
      traduction[nombre] = table_traduction[i][1] ;
    }

    adn = scanner.nextLine();
    System.out.println(traduction(N, M, traduction, adn));
  }
}