1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
| package taxe3;
import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import taxe3.taxe3;
public class taxe3 {
/**
* Constructeur
*/
public taxe3() {
int tableau[] = null;
int[] tableaun=new int [10000];
int[] tableaur=new int [2720];
int a=0;
int p=1;
try{
File ff=new File("C:\\salva\\resultat.txt"); // définir l'arborescence
ff.createNewFile();
FileWriter ffw=new FileWriter(ff);
ffw.write("****** "); // écrire une ligne dans le fichier resultat.txt
ffw.write("\r\n"); // forcer le passage à la ligne
ffw.close(); // fermer le fichier à la fin des traitements
} catch (Exception e) {}
try (BufferedReader b = new BufferedReader(new FileReader(new File("c:/java/taxe.txt")))) {
String line;
// Lecture du fichier ligne par ligne. Cette boucle se termine
// quand la méthode retourne la valeur null.
while ((line = b.readLine()) != null) {
String[] args = line.split("\\s+");
int[] lecture = new int[args.length - 1]; // on crée un tableau
// temporaire pour
// la lecture
for (int i = 1; i < args.length; i++) {
lecture[i - 1] = Integer.parseInt(args[i]);
}
if (tableau == null) {
tableau = lecture;
} else { // on va créer un tableau temporaire pour copier les 2
// autres dedans
int[] temp = new int[tableau.length + lecture.length];
System.arraycopy(tableau, 0, temp, 0, tableau.length); // copie tableau dans temp
System.arraycopy(lecture, 0, temp, tableau.length, lecture.length); // copie lecture dans temp (même remarque que ligne précédente)
tableau = temp;
}
}
} catch (IOException e) {
e.printStackTrace();
}
// affichage
// Comptage
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for (Integer item : tableau) {
Integer nombre = map.get(item);
if (nombre == null) {
nombre = 0;
}
nombre++;
map.put(item, nombre);
}
// Affichage
for (Integer key : map.keySet()) {
Integer nombre = map.get(key);
System.out.println("[" + key + "] --> " + nombre);
}
System.out.println("Valeurs dans tableau : ");
for (int i = 0; i < tableau.length; i++) {
System.out.print(tableau[i]);
if (((i + 1) % 5) == 0) {
System.out.println();
} else {
System.out.print(" ");
}
}
int indiceTableau = 0;
int[] tableauIndiceCherche = new int[tableau.length];
int[] tableauIndiceTrouve = new int[tableau.length];
for (int i = 0; i < tableau.length - 1; i++) {
int indiceTrouve = recherche(tableau[i], tableau, i + 1);
if (indiceTrouve >= 0) {
// par exemple
tableauIndiceCherche[indiceTableau] = i;
tableauIndiceTrouve[indiceTableau] = indiceTrouve;
indiceTableau++; // on passe à la case suivante
}
}
// afichage des résultats
for(int i=0; i<indiceTableau; i++) {
System.out.println("La valeur tableau[" + tableauIndiceCherche[i]/5+"]="+tableau[tableauIndiceCherche[i]]+" a été trouvée en double en position " + (tableauIndiceTrouve[i]/5) + ": tableau["+tableauIndiceTrouve[i]/5+"]="+tableau[tableauIndiceTrouve[i]]);
//System.out.println(tableau[tableauIndiceTrouve[i]]);
a=(tableauIndiceTrouve[i]/5)-(tableauIndiceCherche[i]/5);
tableaun[i]=a;
System.out.println(tableaun[i]);
//tableau2[i]=(tableauIndiceTrouve[i]/5);
}
Arrays.sort(tableauIndiceTrouve);
int times[] = new int[indiceTableau];
for(int i=0; i<indiceTableau; i++){
int number = tableauIndiceTrouve[i]/5;
for(int ii=0; ii<indiceTableau; ii++){
if(number == tableauIndiceTrouve[ii]){
times[i]++;
}
}
}
int tt=0;
int tt1=0;
int tt3=0;
int memo[]= new int[6];
int memo2[]= new int[6];
for(int ii=0; ii<indiceTableau; ii++)
{
if (tt == 5)
{ System.out.println(" ");
System.out.println("------- ");
tt=0;
tt1=1;
tt3=0;
for(int ii2=ii; ii2<indiceTableau; ii2++){
memo2[tt1]=tableaun[ii];
if (tt1 == 5)
{
for (int ii3=1;ii3>=5; ii3++)
{
for (int ii4=1;ii4>=5; ii4++)
if (memo[ii3]==memo2[ii4])
{
tt3=tt3+1;
}
}
try{
File ff=new File("C:\\salva\\resultat.txt"); // définir l'arborescence
FileWriter ffw=new FileWriter(ff,true);
ffw.write(memo[1]+" "+memo[2]+" "+memo[3]+" "+memo[4]+" "+memo[5]+"="+tt3); // écrire une ligne dans le fichier resultat.txt
ffw.write("\r\n"); // forcer le passage à la ligne
ffw.close(); // fermer le fichier à la fin des traitements
} catch (Exception e) {}
tt1=0; }
}
}
}
tt=tt+1;
// System.out.println("The number " + tableauIndiceTrouve[ii]/5 + " is repeted " + times[ii] + " times");
System.out.print(" "+ tableaun[ii]);
tableaur[tableaun[ii]]=tableaur[tableaun[ii]]+1;
memo[tt]=tableaun[ii];
//System.out.println(" test "+ tableaur[tableaun[ii]]+" "+tableaun[ii]);
try{
File ff=new File("C:\\salva\\resultat.txt"); // définir l'arborescence
FileWriter ffw=new FileWriter(ff,true);
ffw.write(tableaun[ii]+" "); // écrire une ligne dans le fichier resultat.txt
if (p >= 5)
{
p=0;
ffw.write("\r\n"); // forcer le passage à la ligne
}
ffw.close(); // fermer le fichier à la fin des traitements
} catch (Exception e) {}
p=p+1;
}
for(int ii=1; ii<100; ii++){
// System.out.println(" nunero total "+ ii+" numero "+tableaur[ii]);
}}
public static int recherche(int maValeur, int[] tab, int depart) {
int monIndice = -1;
for (int i = depart; monIndice == -1 && i < tab.length; i++) {
if (maValeur == tab[i]) {
// System.out.println(i);
monIndice = i;
}
}
return monIndice;
}
/**
* MAIN
*/
public static void main(String[] args) {
// On lance notre lire fichier
new taxe3();
}
} |
Partager