Datei einlesen und etwas herausfiltern
-
-
Du kannst mit fstreams die date wortweise einlesen, dann per std::tolower() + std::foreach() dafür sorgen, dass dir die großbuchstablen nicht in den weg kommen und dann mit std::reverse() und std::string operator==() überprüfen ob das wort vor-und rückwärts gleich ist.There are only 10 types of people in the world: Those who understand binary, and those who don't.
Download meines ersten Spiels:HIER
Über Feedback würde ich mich freuen -
Danke! Ich werds versuchen und falls ich nicht weiterkommen sollte, dann melde ich mich nochmals bei dir.
lg -
Diese Wörter nennt man übrigens [wikipedia='http://de.wikipedia.org/wiki/Palindrom']Palindrom[/wikipedia].~ mfg SeBa
Ich beantworte keine PMs zu Computer-/Programmierproblemen. Bitte wendet euch an das entsprechende Forum.
[Blockierte Grafik: http://i.creativecommons.org/l/by-sa/3.0/80x15.png] -
Hier eine rekursive Lösung in C.
Quellcode
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- void toLower(char* text, int len);
- int palindrom(const char* text, int firstIndex, int lastIndex);
- int main(void) {
- char text[20];
- while(strcmp(text, "quit")) {
- printf("Eingabe: ");
- gets(text);
- toLower(text, strlen(text));
- if(palindrom(text, 0, strlen(text)-1))
- printf("%s ist ein Palindrom\n", text);
- }
- return 0;
- }
- void toLower(char* text, int len) {
- for(int i=0; i<len; i++) {
- if((text[i] >= 'A') && (text[i] <= 'Z'))
- text[i] += 32;
- }
- }
- int palindrom(const char* text, int firstIndex, int lastIndex) {
- if(firstIndex >= lastIndex)
- return 1;
- if(text[firstIndex] == text[lastIndex])
- return 1 * palindrom(text, firstIndex+1, lastIndex-1);
- else
- return 0;
- }
-
Teilen
- Facebook 0
- Twitter 0
- Google Plus 0
- Reddit 0
-
Benutzer online 1
1 Besucher
-
Tags
- de
- http:
- HTML
- www
- Delphi
- cpp
- TXT
- string
- easy-coding
- Python
- Text
- perl
- n
- zahlen
- wort
- Datei
- auslesen
- C
- informationen
- include
- Daten
- quelltext
- filtern
- *
- void
- stelle
- heißt
- textdatei
- kommentare
- spalten
- char
- einlesen
- wörter
- heraus
- const
- rückwärts
- vorwärts
- palindrom
- herausfiltern
- Welcher
- ToLower
- gelesen
- Komponist
- gleich?
- rausfiltern
- datei-einlesen-und-etwas-herau
- filtert
- wortweise