Суть программы 1:
Есть некоторый текстовый файл, который содержит строки. Написать программу для подсчета числа строк, которые:
1) начинаються и оканчиваються одной и той же литерой;
2) состоят из одинаковых литер.
Код программы на паскале:
program ex1;
uses crt;
const space: char = ' ';
var t: text;
s: string;
eq1_count, eq_all_count, k: integer;
begin
clrscr;
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 keypressed
end.
program ex2;
uses crt;
const z:array[0..15] of char = ('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
var x,a: integer;
s:string;
begin
clrscr;
writeln('Vvdedite 4uslo v 10-noy sisteme:');
readln(a);
writeln('Vvedite sistemu s4ucleniya:');
readln(x);
s:='';
if a=0 then s:='0' else
if (x<=16) and (x>1) then begin
while a>0 do begin
s:=z[(a mod x)]+s;
a := a div x;
end;
end;
writeln('4uslo v ',x,'-noy sisteme = ', s);
repeat until keypressed
end.
Переводить программу не буду - напишу заново:
#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;
}
Примного благодарен!!!
а как насчет другой программы?
Вот вторая программа:
#include <stdio.h>
#include <string.h>
char *convert(int n, int radix, char *s) {
const char *digit = "0123456789ABCDEF";
int i = 0;
do {
s[i++] = digit[n % radix];
n /= radix;
} while(n);
s[i] = '\0';
strrev(s);
return s;
}
int main() {
int X;
char buffer[50];
puts("X(10) = "); scanf("%d", &X);
printf("X(7) = %s\n", convert(X, 7, buffer));
printf("X(16) = %s\n", convert(X, 16, buffer));
printf("X(2) = %s\n", convert(X, 2, buffer));
return 0;
}
Огромнейшее спасибо.
Народ, помогите написать прогу на С++.
Нужно что то типа Баунс