Подсчитать количество строк и определить строку максимальной длины и вывести на экран количество строк в файле, самую длинную строку и ее длину. на си.
Var A,B,C:integer; Begin C:=365; Read(A,B); if A>1 then C:=C-31; if A=1 then C:=C-B; if A>2 then C:=C-28; if A=2 then C:=C-B; if A>3 then C:=C-31; if A=3 then C:=C-B; if A>4 then C:=C-30; if A=4 then C:=C-B; if A>5 then C:=C-31; if A=5 then C:=C-B; if A>6 then C:=C-30; if A=6 then C:=C-B; if A>7 then C:=C-31; if A=7 then C:=C-B; if A>8 then C:=C-31; if A=8 then C:=C-B; if A>9 then C:=C-30; if A=9 then C:=C-B; if A>10 then C:=C-31; if A=10 then C:=C-B; if A>11 then C:=C-30; if A=11 then C:=C-B; if A>12 then C:=C-31; if A=12 then C:=C-B; Write(C); End.
var a, d, count, i: integer; function CountDay(a: integer): integer; begin if (a >= 1) then countday := 31; if (a >= 2) then countday := 28; if (a >= 3) then countday := 31; if (a >= 4) then countday := 30; if (a >= 5) then countday := 31; if (a >= 6) then countday := 30; if (a >= 7) then countday := 31; if (a >= 8) then countday := 31; if (a >= 9) then countday := 30; if (a >= 10) then countday := 31; if (a >= 11) then countday := 30; if (a >= 12) then countday := 31; end; begin count := 0; write('Введите месяц: '); readln(a); write('Введите день: '); readln(d); if (a <= 0)or(a > 12)or(d <= 0)or(d > countday(a)) then writeln('Ошшибка в данных!') else begin for i:=a to 12 do count := count + countday(i); count := count - d; writeln('До нового года осталось ', count, ' дней.'); end; end.
#include <stdlib.h>
#include <locale.h>
#include <string.h>
//имя файла
#define FileName "file.txt"
//Максимально возможная длина строки (выделение памяти)
#define l_str 255
int main() {
setlocale(LC_ALL, "rus");
FILE *t = fopen(FileName, "r");
if (t == NULL) {
printf("Файл не найден\n");
}
else {
//Текущая строка
char *s = (char*) malloc(sizeof(char) * l_str);
//Максимальная строка
char *s_max = (char*)malloc(sizeof(char) * l_str);
//Кол-во строк
int k_str = 0;
//Максимальная длина строки
int l_max = 0;
while (!feof(t)) {
fgets(s, l_str, t);
//Длина текущей строки
int l = strlen(s);
if (l > l_max)
{ l_max = l;
strcpy(s_max, s);
} k_str++;
}
//Вывод результата:
printf("Строк в файле: %d\n", k_str);
printf("Максимальная строка, длинной %d:\n", l_max-1);
puts(s_max);
}
fclose(t);
printf("\n");
system("pause");
return 0;
}