Advertisement
roronoa

maj ébauche dérivée cos sin

Jul 14th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.07 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4.  
  5. class Solution {
  6.  
  7.     public static void main(String args[])
  8.     {
  9.         Scanner in = new Scanner(System.in);
  10.         int n = in.nextInt();
  11.         if (in.hasNextLine())
  12.         {
  13.             in.nextLine();
  14.         }
  15.         String F = in.nextLine();
  16.         for(int i = 0; i < n; i++)
  17.         {
  18.             F = d(F);
  19.         }
  20.          
  21.         System.out.println(F);
  22.     }
  23.     public static String d(String e)
  24.     {
  25.  
  26.         String fonction = e.split(" ")[0].replaceAll("[^a-z]","");
  27.         String tmp1 = e.split(" ")[0].replaceAll("[^0-9-]","");
  28.         int facteur=0;
  29.         if(tmp1.length() == 1 && tmp1.charAt(0) == '-')
  30.             tmp1 += 1;
  31.         if(tmp1.length() == 0)
  32.             facteur = 1;
  33.         else
  34.          facteur = Integer.parseInt(tmp1);
  35.         if(facteur == 0)
  36.             facteur = 1;
  37.         String tmp2 = e.split(" ")[1].replaceAll("[^0-9-]","");
  38.         int facteurX = 0;
  39.         if(tmp2.length() == 1 && tmp2.charAt(0) == '-')
  40.             tmp2 += 1;
  41.         if(tmp2.length() == 0)
  42.             facteurX = 1;
  43.         else
  44.             facteurX = Integer.parseInt(tmp2);
  45.         String retour = "";
  46.         if(fonction.equals("sin"))
  47.         {
  48.             int n = facteurX * facteur;
  49.             if(n != 1 && n != -1)
  50.                 retour += n;
  51.             if(n == -1)
  52.                 retour += "-";
  53.             retour += "cos ";
  54.             if(facteurX != 1 && facteur != -1)  
  55.                 retour += facteurX;
  56.             if(facteurX == -1)
  57.                 retour += "-";
  58.             retour += "x";
  59.         }
  60.          else
  61.         {
  62.             int n = facteurX * facteur * -1;
  63.             if(n != 1 && n != -1)
  64.                 retour += n;
  65.             if(n == -1)
  66.                 retour += "-";
  67.             retour += "sin ";
  68.             if(facteurX != 1 && facteur != -1)  
  69.                 retour += facteurX;
  70.             if(facteurX == -1)
  71.                 retour += "-";
  72.             retour += "x";
  73.         }
  74.         return retour;
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement