Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.math.*;
- class Solution {
- public static void main(String args[])
- {
- Scanner in = new Scanner(System.in);
- int n = in.nextInt();
- if (in.hasNextLine())
- {
- in.nextLine();
- }
- String F = in.nextLine();
- for(int i = 0; i < n; i++)
- {
- F = d(F);
- }
- System.out.println(F);
- }
- public static String d(String e)
- {
- String fonction = e.split(" ")[0].replaceAll("[^a-z]","");
- String tmp1 = e.split(" ")[0].replaceAll("[^0-9-]","");
- int facteur=0;
- if(tmp1.length() == 1 && tmp1.charAt(0) == '-')
- tmp1 += 1;
- if(tmp1.length() == 0)
- facteur = 1;
- else
- facteur = Integer.parseInt(tmp1);
- if(facteur == 0)
- facteur = 1;
- String tmp2 = e.split(" ")[1].replaceAll("[^0-9-]","");
- int facteurX = 0;
- if(tmp2.length() == 1 && tmp2.charAt(0) == '-')
- tmp2 += 1;
- if(tmp2.length() == 0)
- facteurX = 1;
- else
- facteurX = Integer.parseInt(tmp2);
- String retour = "";
- if(fonction.equals("sin"))
- {
- int n = facteurX * facteur;
- if(n != 1 && n != -1)
- retour += n;
- if(n == -1)
- retour += "-";
- retour += "cos ";
- if(facteurX != 1 && facteur != -1)
- retour += facteurX;
- if(facteurX == -1)
- retour += "-";
- retour += "x";
- }
- else
- {
- int n = facteurX * facteur * -1;
- if(n != 1 && n != -1)
- retour += n;
- if(n == -1)
- retour += "-";
- retour += "sin ";
- if(facteurX != 1 && facteur != -1)
- retour += facteurX;
- if(facteurX == -1)
- retour += "-";
- retour += "x";
- }
- return retour;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement