-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
163 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright 2024 Massimo Santini | ||
This file is part of "Programmazione 2 @ UniMI" teaching material. | ||
This is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This material is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this file. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package it.unimi.di.prog2.h11; | ||
|
||
import java.util.Scanner; | ||
|
||
/** A class to test some methods of {@link Poly}. */ | ||
public class PolyClient { | ||
|
||
/** . */ | ||
private PolyClient() {} | ||
|
||
/** | ||
* Tests some methods of {@link Poly}. | ||
* | ||
* <p>Starting from term \( t_0 = 0 \) reads a list of \( t_i \) of terms from the standard input, | ||
* given as a (coefficient, degree) pairs, and computes the polynomial \( t_0 + t_1 + t_2 \cdots | ||
* \), emitting in the standard output the pairs "coefficient degree" for every term in the result | ||
* (in increasing order of degree). | ||
* | ||
* @param args not used. | ||
*/ | ||
public static void main(String[] args) { | ||
Poly result = new Poly(); | ||
try (Scanner s = new Scanner(System.in)) { | ||
while (s.hasNextInt()) { | ||
Poly term = new Poly(s.nextInt(), s.nextInt()); | ||
result = result.add(term); | ||
} | ||
} | ||
for (int d = 0; d <= result.degree(); d++) System.out.println(result.coeff(d) + " " + d); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright 2024 Massimo Santini | ||
This file is part of "Programmazione 2 @ UniMI" teaching material. | ||
This is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This material is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this file. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package it.unimi.di.prog2.h11; | ||
|
||
import java.util.Scanner; | ||
|
||
/** A class to test some methods of {@link SparsePoly}. */ | ||
public class SparsePolyClient { | ||
|
||
/** . */ | ||
private SparsePolyClient() {} | ||
|
||
/** | ||
* Tests some methods of {@link SparsePoly}. | ||
* | ||
* <p>Starting from term \( t_0 = x + 1 \) reads a list of \( t_i \) of terms from the standard | ||
* input, given as a (coefficient, degree) pairs, and computes the polynomials \( p_{i+1} = p_i | ||
* \codt t_i + t_i \) emitting in the standard output the pairs "coefficient degree" for every | ||
* term (in increasing order of degree) of the last computed polynomial. | ||
* | ||
* @param args not used. | ||
*/ | ||
public static void main(String[] args) { | ||
SparsePoly result = new SparsePoly(1, 1).add(new SparsePoly(-1, 0)); | ||
try (Scanner s = new Scanner(System.in)) { | ||
while (s.hasNextInt()) { | ||
SparsePoly term = new SparsePoly(s.nextInt(), s.nextInt()); | ||
result = result.mul(term).add(term); | ||
} | ||
} | ||
for (int d = 0; d <= result.degree(); d++) System.out.println(result.coeff(d) + " " + d); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
s09 |