SHOW:
|
|
- or go back to the newest paste.
| 1 | using System; | |
| 2 | using System.Collections.Generic; | |
| 3 | using System.Linq; | |
| 4 | using System.Text; | |
| 5 | ||
| 6 | namespace HA_III_Höchstzahlverfahren | |
| 7 | {
| |
| 8 | ||
| 9 | class Program | |
| 10 | {
| |
| 11 | static void Main(string[] args) | |
| 12 | {
| |
| 13 | Console.WriteLine("Darauf entfallen wieviele Stimmen auf Partei A");
| |
| 14 | int stimmenA=Convert.ToInt32(Console.ReadLine()); | |
| 15 | ||
| 16 | Console.WriteLine("Darauf entfallen wieviele Stimmen auf Partei B");
| |
| 17 | int stimmenB = Convert.ToInt32(Console.ReadLine()); | |
| 18 | ||
| 19 | Console.WriteLine("Darauf entfallen wieviele Stimmen auf Partei C");
| |
| 20 | int stimmenC = Convert.ToInt32(Console.ReadLine()); | |
| 21 | ||
| 22 | Console.WriteLine("Wieviele Sitze sind zu verteilen?");
| |
| 23 | int sitzeGesamt = Convert.ToInt32(Console.ReadLine()); | |
| 24 | ||
| 25 | ||
| 26 | List<int> zahlen=new List<int>(); | |
| 27 | ||
| 28 | ||
| 29 | //geteilt durch 1 hinzufügen^^ | |
| 30 | zahlen.Add(stimmenA); | |
| 31 | zahlen.Add(stimmenB); | |
| 32 | zahlen.Add(stimmenC); | |
| 33 | //hoechstzahlen berechnen. es müssen auf jeden fall mehr zahlen als sitze berechnet werden. anzahltesten berechnet dann genau wieoft geteilt werden muss | |
| 34 | int i=2; | |
| 35 | while(!anzahltesten(zahlen)){
| |
| 36 | zahlen.Add(stimmenA/i); | |
| 37 | zahlen.Add(stimmenB/i); | |
| 38 | zahlen.Add(stimmenC/i); | |
| 39 | i++; | |
| 40 | } | |
| 41 | Console.WriteLine("i: "+i);
| |
| 42 | listausgabe(zahlen); | |
| 43 | int stimmenanzahla=0; | |
| 44 | int stimmenanzahlb=0; | |
| 45 | int stimmenanzahlc=0; | |
| 46 | int groeste=0; | |
| 47 | //stimmanteile nun ausrechnen | |
| 48 | for(int z=0;z<sitzeGesamt;z++){ //soviele höchstzahlen werden gewertet, jedes mal die höchste suchen
| |
| 49 | for(int u=0;u<zahlen.Count;u++){ //größte zahl in zahlen suchen
| |
| 50 | if(zahlen[u]>zahlen[groeste]){
| |
| 51 | groeste=u; //index der größten zahl spcihern; | |
| 52 | } | |
| 53 | } | |
| 54 | if(groeste%3==0){
| |
| 55 | stimmenanzahla++; | |
| 56 | }else if((groeste-1)%3==0){
| |
| 57 | stimmenanzahlb++; | |
| 58 | }else{
| |
| 59 | stimmenanzahlc++; | |
| 60 | } | |
| 61 | zahlen[groeste]=0; //damit sie im nächsten durchgang nichtmehr als "große zahl erkannt wird | |
| 62 | } | |
| 63 | Console.WriteLine(stimmenanzahla+" "+stimmenanzahlb+" "+stimmenanzahlc); | |
| 64 | Console.ReadLine(); | |
| 65 | ||
| 66 | } | |
| 67 | ||
| 68 | public static bool anzahltesten(List<int> hoechstzahlen){
| |
| 69 | if(hoechstzahlen.Count<=3){
| |
| 70 | return false; | |
| 71 | } | |
| 72 | ||
| 73 | ||
| 74 | List<int> zahlen2=new List<int>(); | |
| 75 | //alle bis auf die letzen 3 in die neue liste kopieren | |
| 76 | for(int i=0;i<(hoechstzahlen.Count-3);i++){
| |
| 77 | zahlen2.Add(hoechstzahlen[i]); | |
| 78 | } | |
| 79 | zahlen2.Sort(); | |
| 80 | ||
| 81 | Console.WriteLine("TESTAUSGABE...");
| |
| 82 | Console.WriteLine("hoechstzahlen.Count: "+hoechstzahlen.Count);
| |
| 83 | Console.WriteLine("zahlen2.Count: "+zahlen2.Count);
| |
| 84 | Console.WriteLine("zahlen2:");
| |
| 85 | for(int i=0;i<zahlen2.Count;i++){
| |
| 86 | Console.Write(zahlen2[i]+" "); | |
| 87 | } | |
| 88 | Console.WriteLine(); | |
| 89 | Console.WriteLine("hoechstzahlen:");
| |
| 90 | for(int i=0;i<hoechstzahlen.Count;i++){
| |
| 91 | Console.Write(hoechstzahlen[i]+" "); | |
| 92 | } | |
| 93 | Console.WriteLine(); | |
| 94 | Console.WriteLine("TESTAUSGABE...ENDE");
| |
| 95 | //die letzen 3 zahlen aus hoechstzahlen müssen nun alle kleiner als die ersten 3 aus zahlen2 sein | |
| 96 | if(zahlen2[0]>hoechstzahlen[hoechstzahlen.Count-1] && zahlen2[0]>hoechstzahlen[hoechstzahlen.Count-2] && zahlen2[0]>hoechstzahlen[hoechstzahlen.Count-3] && | |
| 97 | zahlen2[1]>hoechstzahlen[hoechstzahlen.Count-1] && zahlen2[1]>hoechstzahlen[hoechstzahlen.Count-2] && zahlen2[1]>hoechstzahlen[hoechstzahlen.Count-3] && | |
| 98 | zahlen2[2]>hoechstzahlen[hoechstzahlen.Count-1] && zahlen2[2]>hoechstzahlen[hoechstzahlen.Count-2] && zahlen2[2]>hoechstzahlen[hoechstzahlen.Count-3]){
| |
| 99 | ||
| 100 | return true; | |
| 101 | } | |
| 102 | return false; | |
| 103 | } | |
| 104 | ||
| 105 | public static void listausgabe(List<int> hoechstzahlen){
| |
| 106 | Console.WriteLine("hoechstzahlen.Count: "+hoechstzahlen.Count);
| |
| 107 | Console.WriteLine("A B C");
| |
| 108 | for(int i=0;i<hoechstzahlen.Count;i++){
| |
| 109 | Console.Write(hoechstzahlen[i]+" "); | |
| 110 | if((i!=0)&&(i%3==0)){
| |
| 111 | Console.WriteLine("");
| |
| 112 | } | |
| 113 | } | |
| 114 | ||
| 115 | } | |
| 116 | ||
| 117 | } | |
| 118 | } |