<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[auswertung von Txt]]></title><description><![CDATA[<p>Hallo,<br />
ich muss eine Txt folgender Form auswerten:</p>
<p>K 10 os<br />
7 Q s pot<br />
usw.</p>
<p>Als erstes stehen die zwei Karten da. Als nächstes die Farben (s = Gleiche<br />
Farbe; os = Ungleiche Farbe) und als letztes kann noch pot da stehen, falls<br />
jemand bei dieser Hand den Pot gewonnen hat.</p>
<p>Ich muss jetzt in einer Tabelle die Anzahl der Hände auflisten (s und os sind<br />
unterschiedliche Hände) und dazu noch zu jeder Hand die Anzahl der Pöte).</p>
<p>Ich weiß jetzt nicht wie ich das in einer Tabelle unterbringen soll. Ich hab<br />
es mir wie folgt vorgestellt:</p>
<pre><code>Hand | Anzahl | Anzahl Pöte
     | s   os | s        os
A A  | 0    2 | 0         1
usw.
</code></pre>
<p>(Ich habe es in Codeklammern gefasst, damit der Einzug bleibt)</p>
<p>Also eine zweidimensionale Tabelle. Aber wie soll ich von Hand zum Index in der<br />
Tabelle kommen? Außerdem ist es hirnlos in der Tabelle K 10 und 10 K zu haben.<br />
Also immer nur eine Version.</p>
<p>Danke im Voraus!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/209115/auswertung-von-txt</link><generator>RSS for Node</generator><lastBuildDate>Mon, 12 Oct 2026 12:38:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/209115.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 26 Mar 2008 19:47:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to auswertung von Txt on Wed, 26 Mar 2008 19:47:50 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich muss eine Txt folgender Form auswerten:</p>
<p>K 10 os<br />
7 Q s pot<br />
usw.</p>
<p>Als erstes stehen die zwei Karten da. Als nächstes die Farben (s = Gleiche<br />
Farbe; os = Ungleiche Farbe) und als letztes kann noch pot da stehen, falls<br />
jemand bei dieser Hand den Pot gewonnen hat.</p>
<p>Ich muss jetzt in einer Tabelle die Anzahl der Hände auflisten (s und os sind<br />
unterschiedliche Hände) und dazu noch zu jeder Hand die Anzahl der Pöte).</p>
<p>Ich weiß jetzt nicht wie ich das in einer Tabelle unterbringen soll. Ich hab<br />
es mir wie folgt vorgestellt:</p>
<pre><code>Hand | Anzahl | Anzahl Pöte
     | s   os | s        os
A A  | 0    2 | 0         1
usw.
</code></pre>
<p>(Ich habe es in Codeklammern gefasst, damit der Einzug bleibt)</p>
<p>Also eine zweidimensionale Tabelle. Aber wie soll ich von Hand zum Index in der<br />
Tabelle kommen? Außerdem ist es hirnlos in der Tabelle K 10 und 10 K zu haben.<br />
Also immer nur eine Version.</p>
<p>Danke im Voraus!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1480953</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1480953</guid><dc:creator><![CDATA[*D*]]></dc:creator><pubDate>Wed, 26 Mar 2008 19:47:50 GMT</pubDate></item><item><title><![CDATA[Reply to auswertung von Txt on Wed, 26 Mar 2008 20:07:29 GMT]]></title><description><![CDATA[<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1480970</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1480970</guid><dc:creator><![CDATA[*D*]]></dc:creator><pubDate>Wed, 26 Mar 2008 20:07:29 GMT</pubDate></item><item><title><![CDATA[Reply to auswertung von Txt on Thu, 27 Mar 2008 09:47:41 GMT]]></title><description><![CDATA[<p>Hi D,</p>
<p>Ich würd das alles in ne map packen (Paar von Hand und Statitik) und die Daten<br />
dann pro eingelesene Zeile aktualisieren.</p>
<p>Ich dachte da an sowas:</p>
<pre><code class="language-cpp">#include &lt;map&gt;
#include &lt;iostream&gt;

class Statistic{

private:
	unsigned int wonHand;

public:
	Statistic() : wonHand(0){
	}

	void increaseWonHand(){
		++wonHand;
	}

	unsigned int countWonHand(){
		return wonHand;
	}
};

class Hand{
	typedef unsigned int CardValue;

	CardValue value1;
	CardValue value2;
	bool suited;

public:
	Hand(Hand::CardValue v1, Hand::CardValue v2, bool suited): value1(v1), value2(v2), suited(suited){
		if(v2&gt;v1){
			std::swap(value1, value2);
		}
	}

	char getAbbreviation(CardValue v) const{
		switch(v){
			case 8:
				return 'T';
			case 9:
				return 'J';
			case 10:
				return 'Q';
			case 11:
				return 'K';
			case 12:
				return 'A';
			default:
				return (char)('2'+v);
		}
	}

	void printHand(std::ostream&amp; s) const {
		s &lt;&lt; getAbbreviation(value1) &lt;&lt; getAbbreviation(value2);
		if(suited)
			s &lt;&lt; 's';
		else
			s &lt;&lt; 'o';
	}

	bool operator&lt;(const Hand&amp; h) const { 
        if(this-&gt;value1 &lt; h.value1)
			return true;
		else{
			if(this-&gt;value1 == h.value1){
				if(this-&gt;value2 &lt; h.value2)
					return true;
				else if(this-&gt;value2 == h.value2){
					return !this-&gt;suited &amp;&amp; h.suited;
				}
			}
		}
		return false;
	}

};

std::ostream&amp; operator &lt;&lt;(std::ostream&amp; s, const Hand&amp; card){
	card.printHand(s);
	return s;
}

int main(){
	std::map&lt;Hand, Statistic&gt; map;
	for(unsigned int i=0; i&lt;13; ++i){
		for(unsigned int j=i; j&lt;13; ++j){
			map.insert(std::make_pair(Hand(i,j, false),Statistic()));
			if(i!=j){
				map.insert(std::make_pair(Hand(i,j, true),Statistic()));
			}
		}		
	}
	Statistic&amp; statistic = map[Hand(12,11, false)];
	statistic.increaseWonHand();
	statistic = map[Hand(11,12, false)];
	statistic.increaseWonHand();
	for(std::map&lt;Hand, Statistic&gt;::iterator it= map.begin(); it != map.end(); ++it){
		std::cout &lt;&lt; (*it).first &lt;&lt; &quot;: &quot; &lt;&lt; (*it).second.countWonHand() &lt;&lt; std::endl;
	}
	return 0;
}
</code></pre>
<p>Natürlich mußt du die Ausgabe an die Tabelle anpassen. Wenn du Probleme beim<br />
einlesen der Daten aus der Datei hast, kannste dich ja nochmal melden.<br />
Irgendwer hilft bestimmt.</p>
<p>Gruß,<br />
CSpille</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1481200</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1481200</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Thu, 27 Mar 2008 09:47:41 GMT</pubDate></item><item><title><![CDATA[Reply to auswertung von Txt on Thu, 27 Mar 2008 20:07:32 GMT]]></title><description><![CDATA[<p>Hallo D,</p>
<p>das Hauptproblem dürfte das Einlesen sein. Besonders schwierig ist es hier deshalb, weil der Test 'pot' einmal da sein kann und einmal nicht. Ich unterstelle mal, dass hinter einer 'Hand' immer ein Zeilenumbruch kommt. Das ganze ist ein etwas ungünstiges Format.<br />
Standard-Vorgehen .. wie immer braucht man zunächst eine Sruktur/Klasse, die man liest und diese wird dann mit dem Streaming-operator ausgestattet:</p>
<pre><code class="language-cpp">void trim( std::string&amp; str ) // besser: boost::trim
{
    while( !str.empty() &amp;&amp; isspace( str[0] ) )
        str.erase( str.begin() );
    for( std::string::iterator i; !str.empty() &amp;&amp; isspace( *(i = str.end()-1) ); )
        str.erase( i );
}
class Hand
{
public:
    enum pot_type { kein_pot, pot };
    enum farben_type { os, s };

    // -- diese Funktion liest eine 'Hand'
    //    Format: &lt;Karte&gt; &lt;Karte&gt; {s|os} [pot] LF
    friend std::istream&amp; operator&gt;&gt;( std::istream&amp; in, Hand&amp; hnd )
    {
        // --   die beiden Karten
        if( !(in &gt;&gt; hnd.m_karten.first &gt;&gt; hnd.m_karten.second) )
            return in;
        if( hnd.m_karten.second &gt; hnd.m_karten.first )
            swap( hnd.m_karten.first, hnd.m_karten.second );

        // --   gleiche oder ungleiche Farbe
        std::string f;
        if( in &gt;&gt; f &amp;&amp; f != &quot;s&quot; &amp;&amp; f != &quot;os&quot; )
            in.setstate( std::ios_base::failbit );  // muss 's' oder 'os' sein
        if( !in )
            return in;
        hnd.m_farbengleich = (f == &quot;s&quot;? Hand::s: Hand::os);

        // --   optional 'pot' bis Zeilenende
        std::string txt;
        if( getline( in, txt ) )
        {
            trim( txt );
            if( !txt.empty() &amp;&amp; txt != &quot;pot&quot;)
                in.setstate( std::ios_base::failbit );  // muss 'pot' oder nichts sein
        }
        if( !in )
            return in;
        hnd.m_pot = (txt == &quot;pot&quot;? Hand::pot: Hand::kein_pot);

        return in;
    }

    // --   ein paar Getters
    std::pair&lt; std::string, std::string &gt; kartenpaar() const
    {
        return m_karten;
    }
    bool ist_s() const { return m_farbengleich == Hand::s; }
    bool hat_pot() const { return m_pot == Hand::pot; }

private:
    std::pair&lt; std::string, std::string &gt; m_karten;
    farben_type m_farbengleich;
    pot_type m_pot;
};
</code></pre>
<p>Damit kann man die Datei schon mal lesen. Die Tabelle für die Ausgabe ist als map gut zu realisieren. Aber erstmal braucht man dazu die Zeile einer Tabelle - also</p>
<pre><code class="language-cpp">class Line
{
public:
    Line()
        : m_anz_s( 0 )
        , m_anz_os( 0 )
        , m_anz_poete_s( 0 )
        , m_anz_poete_os( 0 )
    {}

    int m_anz_s;
    int m_anz_os;
    int m_anz_poete_s;
    int m_anz_poete_os;
};
</code></pre>
<p>Wichtig: der Defaultkonstruktor setzt die Member auf 0 - so braucht man sich um das Anlegen nicht vorhandener map-Elemente nicht mehr zu kümmern.</p>
<p>Damit ausgerüstet wir es ab jetzt übersichtlich:</p>
<pre><code class="language-cpp">#include &lt;algorithm&gt; // swap
#include &lt;fstream&gt;
#include &lt;iomanip&gt; // setw
#include &lt;iostream&gt;
#include &lt;map&gt;
#include &lt;string&gt;

class Hand; // (s.o)
class Line; // (s.o)

int main()
{
    using namespace std;
    typedef map&lt; std::pair&lt; std::string, std::string &gt;, Line &gt; Tabelle;
    Tabelle tabelle;
    ifstream datei(&quot;input.txt&quot;);
    for( Hand hand; datei &gt;&gt; hand;  )  // Hände aus Datei lesen bis zum Datei-Ende
    {
        // Informationen aus einer Hand in die passende Zeile ablegen
        Line&amp; line = tabelle[ hand.kartenpaar() ];
        if( hand.ist_s() )
        {
            ++line.m_anz_s;
            if( hand.hat_pot() )
                ++line.m_anz_poete_s;
        }
        else // Hand ist os
        {
            ++line.m_anz_os;
            if( hand.hat_pot() )
                ++line.m_anz_poete_os;
        }
    }

    // --  ab hier erfolgt die Ausgabe ...
    // Tabellenkopf ausgeben
    cout &lt;&lt; &quot;Hand  | Anzahl | Anzahl Pöte&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;      | s   os | s        os&quot; &lt;&lt; endl;
    // Tabelle ausgeben
    for( Tabelle::iterator i = tabelle.begin(); i != tabelle.end(); ++i )
    {
        cout &lt;&lt; setw(2) &lt;&lt; i-&gt;first.first &lt;&lt; &quot; &quot; &lt;&lt; setw(2) &lt;&lt; i-&gt;first.second &lt;&lt; &quot; | &quot;
            &lt;&lt; setw(2) &lt;&lt; i-&gt;second.m_anz_s &lt;&lt; &quot; &quot; &lt;&lt; setw(3) &lt;&lt; i-&gt;second.m_anz_os &lt;&lt; &quot; | &quot;
            &lt;&lt; setw(2) &lt;&lt; i-&gt;second.m_anz_poete_s &lt;&lt; &quot; &quot; &lt;&lt; setw(8) &lt;&lt; i-&gt;second.m_anz_poete_os 
            &lt;&lt; endl;
    }
    return 0;
}
</code></pre>
<p>.. schreibt man Pot nicht mit zwei 't'?</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1481699</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1481699</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Thu, 27 Mar 2008 20:07:32 GMT</pubDate></item></channel></rss>