Advertisement
Guest User

Untitled

a guest
Jan 15th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4. #include <string>
  5. #include <vector>
  6. #include <sstream>
  7. #include <limits> // numeric_limits
  8.  
  9. void MatrixMase(std::string Datei_Name, long * hoehe, long * breite);
  10.  
  11. std::string BestimmteZeileAusDatei(std::string Datei_Name, long Gesuchte_Zeile_Wert);
  12.  
  13. long BestimmtenWertAusZeileLesen(std::string Gesuchte_Zeile_Inhalt, long Stelle);
  14.  
  15. long LeerzeichenAbstandEinerZeileErmitteln(std::string Gesuchte_Zeile_Inhalt);
  16.  
  17.  
  18. int main ()
  19. {
  20. using namespace std;
  21. long hoehe,breite,a,b,c,d,e,wert;
  22. a = 0;
  23. b = 4;
  24. c = 0;
  25. d = 0;
  26. e = 0;
  27. wert = 0;
  28. long counter;
  29. using namespace std;
  30. string Datei_Name = "input.pgm";
  31. string Bestimmte_Zeile_Aus_Datei;
  32. string Wert_String;
  33. MatrixMase(Datei_Name, &hoehe, &breite);
  34. long MatrixA[breite][hoehe];
  35. Bestimmte_Zeile_Aus_Datei = BestimmteZeileAusDatei( Datei_Name, b);
  36. for(int i = 0; i != (breite * hoehe); i++, a++, c++)
  37. {
  38. Bestimmte_Zeile_Aus_Datei = BestimmteZeileAusDatei( Datei_Name, b);
  39. if(a > (Bestimmte_Zeile_Aus_Datei.length() / LeerzeichenAbstandEinerZeileErmitteln(Bestimmte_Zeile_Aus_Datei) - 1))
  40. {
  41. a = 0;
  42. b++;
  43. }
  44. Bestimmte_Zeile_Aus_Datei = BestimmteZeileAusDatei( Datei_Name, b);
  45. for(counter = 0, e = 0; e < a ; counter++)
  46. {
  47. if(Bestimmte_Zeile_Aus_Datei[counter] == ' ')
  48. {
  49. e++;
  50. }
  51. }
  52. Wert_String = ' ';
  53. for(; Bestimmte_Zeile_Aus_Datei[counter] != ' '; counter++)
  54. {
  55. Wert_String += Bestimmte_Zeile_Aus_Datei[counter];
  56. }
  57. stringstream Wert_String_1(Wert_String);
  58. Wert_String_1 >> wert;
  59.  
  60. if(c > breite)
  61. {
  62. c = 0;
  63. d++;
  64. }
  65. MatrixA[c][d] = wert;
  66. }
  67.  
  68. return(0);
  69. }
  70.  
  71.  
  72. void MatrixMase(std::string Datei_Name, long * hoehe, long * breite)
  73. {
  74. using namespace std;
  75. long Gesuchte_Zeile_Wert = 2;
  76. string Gesuchte_Zeile_Inhalt;
  77. Gesuchte_Zeile_Inhalt = BestimmteZeileAusDatei(Datei_Name, Gesuchte_Zeile_Wert);
  78. *breite = BestimmtenWertAusZeileLesen(Gesuchte_Zeile_Inhalt, 0);
  79. *hoehe = BestimmtenWertAusZeileLesen(Gesuchte_Zeile_Inhalt, 1 * LeerzeichenAbstandEinerZeileErmitteln( Gesuchte_Zeile_Inhalt));
  80. return;
  81.  
  82. }
  83.  
  84. std::string BestimmteZeileAusDatei(std::string Datei_Name, long Gesuchte_Zeile_Wert)
  85. {
  86. using namespace std;
  87.  
  88. ifstream Datei(Datei_Name.c_str());
  89. if( !Datei.is_open()){ return("Fehler1");};
  90. for( ; Gesuchte_Zeile_Wert > 1; --Gesuchte_Zeile_Wert)
  91. {
  92. Datei.ignore(numeric_limits< streamsize >::max(), '\n' );
  93. }
  94. string Gesuchte_Zeile_Inhalt;
  95. if( !getline( Datei, Gesuchte_Zeile_Inhalt)){ return("Fehler2");};
  96.  
  97. return(Gesuchte_Zeile_Inhalt);
  98. }
  99.  
  100. long BestimmtenWertAusZeileLesen(std::string Gesuchte_Zeile_Inhalt, long Stelle)
  101. {
  102. using namespace std;
  103.  
  104. long strpos = Gesuchte_Zeile_Inhalt.find(" ") + 1;
  105. string Gesuchter_String = Gesuchte_Zeile_Inhalt.substr( Stelle, strpos);
  106. stringstream Gesuchter_Stringsrteam(Gesuchter_String);
  107. long Wert;
  108. Gesuchter_Stringsrteam >> Wert;
  109.  
  110. return(Wert);
  111. }
  112.  
  113.  
  114. long LeerzeichenAbstandEinerZeileErmitteln(std::string Gesuchte_Zeile_Inhalt)
  115. {
  116. return(Gesuchte_Zeile_Inhalt.find(" ") + 1);
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement