matic Posted March 18, 2007 Report Share Posted March 18, 2007 Суть программы: Есть некоторый текстовый файл, который содержит строки. Написать программу для подсчета числа строк, которые: 1) начинаються и оканчиваються одной и той же литерой; 2) состоят из одинаковых литер. Код программы на паскале: program ex1;uses crt;const space: char = ' ';var t: text;s: string;eq1_count, eq_all_count, k: integer;beginclrscr;eq1_count :=0;eq_all_count:=0;assign(t,'file.txt');reset(t); while not eof(t) do begin readln(t, s); while (s[1] = space) and (length(s) > 1 ) do delete(s,1,1);while (s[length(s)] = space) and (length(s) > 1) do delete(s, length(s), 1);if s = '' then continue;if s[1] = s[length(s)] then inc(eq1_count);k:=1;while (s[1]=s[k]) and (k<length(s)) do inc(k);if (k=length(s)) and (k>1) then inc(eq_all_count);end;writeln('4uslo strok,na4unayushihsya i zakan4uvayushihsya odnoy i toy ge literoy = ', eq1_count);writeln;writeln('4uslo strok, sostoyashih iz odinakovih liter = ', eq_all_count);repeat until keypressedend. Я бы был признател тому кто смог бы мне переделат это прогу на язык С++. заранее благодарю. Link to comment Share on other sites More sharing options...
matic Posted March 20, 2007 Author Report Share Posted March 20, 2007 #include <iostream.h>#include <fstream.h>int main() { fstream f; const maxSize = 1024; int len, count_one = 0, count_two = 0; char inBuf[maxSize]; f.open("test_01.txt", ios::in); while(f.getline(inBuf, maxSize)) { if(( (len = f.gcount() - 1) > 1) && (inBuf[0] == inBuf[len - 1])) ++count_one; int T = 1; for(int i = 1; i < len; ++i) if(inBuf[0] == inBuf[i]) T += 1; count_two += ((len > 1) && (T == len)) ? 1 : 0; } cout << " count_one = " << count_one << " count_two = " << count_two << endl; f.close(); return 0;} Помогите найти глюк? Когда запускаю прогу то почему то она нече не выводить? Link to comment Share on other sites More sharing options...
Darhazer Posted March 20, 2007 Report Share Posted March 20, 2007 Уверен что ничто не виводить? В проге на Pascal вы добавили в конце repeat until keypressed чтоб не закрывалось окно, но в C++ коде не добавили ничто чтоб окно не закрылось. Попробуйте запустить программу из командной строке или добавте int tmp; cin >> tmp; в конце. Link to comment Share on other sites More sharing options...
matic Posted March 20, 2007 Author Report Share Posted March 20, 2007 Да нефига.... вообще то вместо репит антил кейпресд на сях пишеться : #include <conio.h> .... .... getch(); Или это то что мой компилятор глючит либо ошибка в самом коде.... Link to comment Share on other sites More sharing options...
matic Posted March 21, 2007 Author Report Share Posted March 21, 2007 Все разобрался. Благодарю всех кто помог. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now