<?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[Konserviertheit eines Strings ermitteln]]></title><description><![CDATA[<p>Servus,</p>
<p>ich will ab einer Grenze von 90 % Konserviertheit den String entwerten. Der String AAAAAAAAABA, sollte also raus, weil A zu oft vorkommt.</p>
<p>Wie prüfe ich da ein Bündel von Strings möglichst geschickt durch?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/284813/konserviertheit-eines-strings-ermitteln</link><generator>RSS for Node</generator><lastBuildDate>Fri, 21 Aug 2026 18:23:58 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/284813.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 08 Apr 2011 15:28:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Konserviertheit eines Strings ermitteln on Fri, 08 Apr 2011 15:28:48 GMT]]></title><description><![CDATA[<p>Servus,</p>
<p>ich will ab einer Grenze von 90 % Konserviertheit den String entwerten. Der String AAAAAAAAABA, sollte also raus, weil A zu oft vorkommt.</p>
<p>Wie prüfe ich da ein Bündel von Strings möglichst geschickt durch?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2046431</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2046431</guid><dc:creator><![CDATA[Jay1980]]></dc:creator><pubDate>Fri, 08 Apr 2011 15:28:48 GMT</pubDate></item><item><title><![CDATA[Reply to Konserviertheit eines Strings ermitteln on Fri, 08 Apr 2011 15:31:54 GMT]]></title><description><![CDATA[<p>zähl die buchstaben und rechne das vorkommen in przent aus<br />
also bei diesem string hier:<br />
aaab -&gt; 3a von 4 buchstaben ==&gt; 75% a's (formel: anzahl/länge *100)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2046434</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2046434</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Fri, 08 Apr 2011 15:31:54 GMT</pubDate></item><item><title><![CDATA[Reply to Konserviertheit eines Strings ermitteln on Fri, 08 Apr 2011 15:55:42 GMT]]></title><description><![CDATA[<p>Okay, also ich nehme das erste Symbol und zähle das Vorkommen von diesem. Dann vergleiche ich, ob das Auftreten die vorher berechnete Schwelle gesprengt hat. Hat es diese Schwelle gesprengt, nehme ich das nächste Symbol, bis keine unbekannten Symbole mehr da sind. Zeitgleich kann ich die bereits bekannten Symbole mitnotieren und wenn die 10 % überschritten sind ausbrechen und das Gezähle aufhören für diesen String ...</p>
<p>Hat da jemand noch ein geschickteres Vorgehen parat?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2046446</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2046446</guid><dc:creator><![CDATA[Jay1980]]></dc:creator><pubDate>Fri, 08 Apr 2011 15:55:42 GMT</pubDate></item><item><title><![CDATA[Reply to Konserviertheit eines Strings ermitteln on Fri, 08 Apr 2011 16:01:49 GMT]]></title><description><![CDATA[<p>Jay1980 schrieb:</p>
<blockquote>
<p>Hat da jemand noch ein geschickteres Vorgehen parat?</p>
</blockquote>
<p>Du gehst den String 1x durch und zählst jede Symbolsorte mit (eine map bietet sich an). Wenn eine Symbolsorte die geforderte Höchsmenge überschreitet, brichst du ab.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2046450</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2046450</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Fri, 08 Apr 2011 16:01:49 GMT</pubDate></item><item><title><![CDATA[Reply to Konserviertheit eines Strings ermitteln on Fri, 08 Apr 2011 22:35:24 GMT]]></title><description><![CDATA[<p>Sehr gut mit dem 'einmal durchgehen' - hier ist mein Versuch:</p>
<pre><code class="language-cpp">void flagImportantColumnsRelatedToIdentity() // TODO umbenennen, dass es um Konsverviertheit geht
    {

        // Methode erkennt Spaltenstrings von mehr als 90 % Konserviertheit und kennzeichnet diese

        cout &lt;&lt; &quot;main - flagImportantColumnsRelatedToIdentity() ....\n&quot;;

        // Map-Verwendung, Spaltenstring-Bildung, siehe Single-Entropie-Berechnung
        typedef map&lt; char, int &gt; SoMapType;
        typedef SoMapType::value_type SoValuePair;
        SoMapType symbolOccuranceList; // eine Liste pro Spalte
        vector&lt; SoMapType &gt; listOfMaps;
        int msaColCounter = 0;
        int msaRowCounter = 0;
        int msaCols = seqan::length(this-&gt;getSequencesList()[ 0 ]);
        int msaRows = seqan::length(this-&gt;getSequencesList());
        seqan::CharString currentSequenceString;
        double schwelle = msaRows * 0.9;
        cout &lt;&lt; &quot;... Schwelle liegt bei &quot; &lt;&lt; schwelle &lt;&lt; endl; // Schwelle ermitteln
        seqan::StringSet&lt;seqan::CharString&gt; colStringList; // TODO in der Methode geht es ohne, aber wenn ich diese Speicher dann hier denke ich.

        // Spalten-Strings bilden, TODO überdenken, ob ich die Spaltenstrings nicht irgendwo direkt ablegen sollte
        for ( msaRowCounter = 0; msaRowCounter &lt; msaRows; msaRowCounter++)
        {
            if ( msaRowCounter == 0 )
            {
                // Anlegen einer Map pro Spalte
                int mapColCounter = 0; 
                for ( mapColCounter = 0; mapColCounter &lt; msaCols; mapColCounter++ )
                {
                    SoMapType symbolOccuranceList;
                    listOfMaps.push_back( symbolOccuranceList );
                }
                cout &lt;&lt; &quot;... eine Map pro Spalte wurde angelegt, gesamt &quot; &lt;&lt; listOfMaps.size() &lt;&lt; endl;
            }

            currentSequenceString = seqan::value( this-&gt;getSequencesList(), msaRowCounter );
            cout &lt;&lt; &quot;... picke currentSequenceString, hier &quot; &lt;&lt; currentSequenceString &lt;&lt; endl;

            char currentChar; // das gepickte Zeichen des Sequenzstrings
            SoMapType currentMap;
            for ( msaColCounter = 0; msaColCounter &lt; msaCols; msaColCounter++ )
            {
                currentMap = listOfMaps.at(msaColCounter);
                cout &lt;&lt; &quot;... aktuelle Map gewählt. \n&quot;;
                //cout &lt;&lt; currentMap &lt;&lt; endl;

                currentChar = currentSequenceString[ msaColCounter ];
                cout &lt;&lt; &quot;... ... currentChar: &quot; &lt;&lt; currentChar &lt;&lt; &quot;; Spalte &quot; &lt;&lt; msaColCounter &lt;&lt; endl;

                // Mapping-Vorgang
                SoMapType::const_iterator soIter;
                soIter = currentMap.find( currentChar );
                if ( soIter != currentMap.end() )
                {
                    currentMap[ currentChar ] += 1;
                    cout &lt;&lt; &quot;... ... Map zu currentChar [key|value][&quot; &lt;&lt; currentChar &lt;&lt; &quot;|&quot; &lt;&lt; currentMap[ currentChar ] &lt;&lt;  &quot;] existiert für currentSequenceString!\n&quot;;
                    // check fuer den aktuellen Key-Value, ob die Schwelle schon erreicht ist
                    if ( currentMap[ currentChar ] &gt; schwelle )
                    {
                        importantColumns.at( msaColCounter ) = 1; // unwichtig
                        cout &lt;&lt; &quot;... ... ... Schwellwert für &quot; &lt;&lt; currentChar &lt;&lt; &quot; getoppt, setze Spalte &quot; &lt;&lt; msaColCounter &lt;&lt; &quot; auf 1 \n&quot;;
                    }
                }
                else // noch nicht drin
                {
                    currentMap.insert( SoValuePair( currentChar, 1 ) );
                    cout &lt;&lt; &quot;... ... Map zu currentChar [key|value][&quot; &lt;&lt; currentChar &lt;&lt; &quot;|&quot; &lt;&lt; currentMap[ currentChar ] &lt;&lt;  &quot;] ist neu für currentSequenceString!\n&quot;;

                    // check fuer den aktuellen Key-Value, ob die Schwelle schon erreicht ist
                    if ( symbolOccuranceList[ currentChar ] &gt; schwelle )
                    {
                        importantColumns.at( msaColCounter ) = 1; // unwichtig
                        cout &lt;&lt; &quot;... ... ... Schwellwert für &quot; &lt;&lt; currentChar &lt;&lt; &quot; getoppt, setze Spalte &quot; &lt;&lt; msaColCounter &lt;&lt; &quot; auf 1 \n&quot;;
                    }
                }
            }
            cout &lt;&lt; &quot;... currentSequenceString zeichenmäßig durchgegangen\n&quot;;
        }
        cout &lt;&lt; &quot;... alle Strings durch\n&quot;;
        cout &lt;&lt; &quot;main -  // flagImportantColumnsRelatedToIdentity()!\n&quot;;
    }
</code></pre>
<p>Irgendetwas mach ich aber mit der Map falsch, die Debug-Meldung sagt mir immer, dass eine neue Map angelegt wird, wenn ich in die zweite Zeile gehe. Es soll aber hier eigentlich die bereits bestehende Map für den ersten Spaltenstring genommen werden. Sieht jemand meinen Fehler ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2046570</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2046570</guid><dc:creator><![CDATA[Jay1980]]></dc:creator><pubDate>Fri, 08 Apr 2011 22:35:24 GMT</pubDate></item><item><title><![CDATA[Reply to Konserviertheit eines Strings ermitteln on Sat, 09 Apr 2011 04:49:38 GMT]]></title><description><![CDATA[<p>Mach mal ein paar Funktionen, bei dem ganzen Zeug kennt sich keiner aus. Oder soll das alles die Funktion sein die prüft, ob ein Zeichen zu oft vorkommt, dann ist sie viel zu kompliziert.</p>
<p>So sollte sie aussehen.</p>
<pre><code class="language-cpp">bool isKonserviert(std::string const&amp; txt)
{
   //hier sollten max 10 Zeilen ausreichen
}
</code></pre>
<p>PS: Warum heißt das Konsverviertheit?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2046581</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2046581</guid><dc:creator><![CDATA[neneneh]]></dc:creator><pubDate>Sat, 09 Apr 2011 04:49:38 GMT</pubDate></item><item><title><![CDATA[Reply to Konserviertheit eines Strings ermitteln on Sat, 09 Apr 2011 05:47:50 GMT]]></title><description><![CDATA[<p>Jay1980 schrieb:</p>
<blockquote>
<p>Irgendetwas mach ich aber mit der Map falsch, die Debug-Meldung sagt mir immer, dass eine neue Map angelegt wird, wenn ich in die zweite Zeile gehe. Es soll aber hier eigentlich die bereits bestehende Map für den ersten Spaltenstring genommen werden. Sieht jemand meinen Fehler ?</p>
</blockquote>
<p>Ohne deinen Code jetzt genau analysiert zu haben:</p>
<p>Überleg mal, was er in Zeile 41 macht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<pre><code class="language-cpp">SoMapType currentMap;
</code></pre>
<p>Falls du es nicht siehst, kuck dir mal folgenden Code an:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

class Foo{
public:
        Foo() : val(0) {std::cout &lt;&lt; &quot;Foo()&quot; &lt;&lt; std::endl;}
        ~Foo() {std::cout &lt;&lt; &quot;~Foo()&quot; &lt;&lt; std::endl;}
        int&amp; value(){ return val;}
private:
        int val;
};

int main(){
        for(int i=0; i&lt;3; i++){
                Foo foo;
                for(int j=0; j&lt;3; j++){
                        std::cout &lt;&lt; foo.value()++ &lt;&lt; std::endl;
                }
        }
}
</code></pre>
<blockquote>
<p>Foo()<br />
0<br />
1<br />
2<br />
~Foo()<br />
Foo()<br />
0<br />
1<br />
2<br />
~Foo()<br />
Foo()<br />
0<br />
1<br />
2<br />
~Foo()</p>
</blockquote>
<p>Gruß,<br />
XSpille</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2046584</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2046584</guid><dc:creator><![CDATA[XSpille]]></dc:creator><pubDate>Sat, 09 Apr 2011 05:47:50 GMT</pubDate></item><item><title><![CDATA[Reply to Konserviertheit eines Strings ermitteln on Sat, 09 Apr 2011 11:58:28 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">using namespace std;
	string text = &quot;AAdfgABBCDHGFG;;:sdfgsfdg!$$%&amp;§WDFGWdfgUJIJ&quot;;
	std::array&lt;size_t, 256&gt; counts = {0};
	for (auto it = text.begin(), end = text.end(); it != end; ++it)
		++counts[static_cast&lt;unsigned char&gt;(*it)];

	cout &lt;&lt; *max_element(counts.begin(), counts.end()) &lt;&lt;
		&quot; / &quot; &lt;&lt; text.size();
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2046670</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2046670</guid><dc:creator><![CDATA[brotbernd]]></dc:creator><pubDate>Sat, 09 Apr 2011 11:58:28 GMT</pubDate></item><item><title><![CDATA[Reply to Konserviertheit eines Strings ermitteln on Sat, 09 Apr 2011 14:43:08 GMT]]></title><description><![CDATA[<p>Ich kann zwar mit dem Begriff &quot;Konserviertheit&quot; nichts anfangen, aber wenn es darum geht, zu gucken, wie oft der häufigste Buchstabe auftritt, könnte man den String auch einfach sortieren, einmal durchlaufen und sich merken, wie groß die größte gruppe von gleichen Buchstaben war.</p>
<pre><code class="language-cpp">int maxfreq(string s)
{
  int len = s.size();
  if (!len) return 0;
  sort(s.begin(),s.end());
  char z = s[0];
  int counter = 1;
  int max_counter = 1;
  for (int i=1; i&lt;len; ++i) {
    char t = s[i];
    if (z==t) {
      ++counter;
    } else {
      max_counter = max(counter,max_counter);
      counter = 1;
      z = t;
    }
  }
  max_counter = max(counter,max_counter);
  return max_counter;
}
</code></pre>
<p>(einfach so runtergetippt ohne zu testen)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2046737</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2046737</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Sat, 09 Apr 2011 14:43:08 GMT</pubDate></item><item><title><![CDATA[Reply to Konserviertheit eines Strings ermitteln on Sat, 09 Apr 2011 15:40:52 GMT]]></title><description><![CDATA[<p>Mal auf brotbernds Idee aufgesetzt:</p>
<pre><code class="language-cpp">#include &lt;algorithm&gt;
#include &lt;cstddef&gt;
#include &lt;iostream&gt;
#include &lt;numeric&gt;
#include &lt;string&gt;

class counter {
public:
  counter() { std::fill(counters_, counters_ + 256, 0); }
  std::size_t operator()(std::size_t n, char c) {
    return std::max(n, ++counters_[static_cast&lt;unsigned char&gt;(c)]);
  }
private:
  std::size_t counters_[256];
};

int main() {
  std::string text = &quot;AAdfgABBCDHGFG;;:sdfgsfdg!$$%&amp;§WDFGWdfgUJIJ&quot;; 
  std::size_t n = std::accumulate(text.begin(), text.end(), 0, counter());

  std::cout &lt;&lt; n &lt;&lt; &quot; / &quot; &lt;&lt; text.size() &lt;&lt; std::endl;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2046760</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2046760</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Sat, 09 Apr 2011 15:40:52 GMT</pubDate></item><item><title><![CDATA[Reply to Konserviertheit eines Strings ermitteln on Sat, 09 Apr 2011 16:42:03 GMT]]></title><description><![CDATA[<p>krümelkacker: Warum lineare Laufzeit gegen O(n*logn) eintauschen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2046785</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2046785</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Sat, 09 Apr 2011 16:42:03 GMT</pubDate></item></channel></rss>