Форум программистов, компьютерный форум, киберфорум
Pascal (Паскаль)
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 5.00/11: Рейтинг темы: голосов - 11, средняя оценка - 5.00
0 / 0 / 0
Регистрация: 20.02.2013
Сообщений: 2
1

Задача про Валентинки

20.02.2013, 17:31. Показов 2167. Ответов 3
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Суть такова. Есть входной файл, в котором первое число - число последующих строк.
каждая последующая строка имеет вид: [кому отправили] пробел [текст поздравления] пробел [от какого класса]. - Так называемые валентинки.
Пример: 10д с праздником 10в
Или
9а гори в аду 11д
...
Требуется вывести на экран те классы, которые отправили валентинок больше чем получили.
Классы с 1 по 11, литера с "А" до "Ж".
Pascal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
var f1,f2:text;
a:array [1..11,1..7] of integer;
s,yx,letter:string;
osh,x,i,j,n:integer;
begin
assign (f1,'in.txt'); reset (f1);
assign (f2,'out.txt'); reset (f2);
readln (f1,n);
for i:=1 to 11 do
for j:=1 to 7 do
a[i,j]:=0;
 
for i:=1 to n do
  BEGIN
    readln (f1,s);
    yx:=copy (s,1,pos (' ',s)-2);
    letter:=copy (s,pos(' ',s)-1,1);
    val (yx,x,osh);
    if osh=0 then
      BEgin 
      if x=1 then begin
          if letter ='à' then a[1,1]:=a[1,1]-1;
          if letter ='á' then a[1,2]:=a[1,2]-1;
          if letter ='â' then a[1,3]:=a[1,3]-1;
          if letter ='ã' then a[1,4]:=a[1,4]-1;
          if letter ='ä' then a[1,5]:=a[1,5]-1;
          if letter ='å' then a[1,6]:=a[1,6]-1;
          if letter ='æ' then a[1,7]:=a[1,7]-1;
          end;
       if x=2 then begin
          if letter ='à' then a[2,1]:=a[2,1]-1;
          if letter ='á' then a[2,2]:=a[2,2]-1;
          if letter ='â' then a[2,3]:=a[2,3]-1;
          if letter ='ã' then a[2,4]:=a[2,4]-1;
          if letter ='ä' then a[2,5]:=a[2,5]-1;
          if letter ='å' then a[2,6]:=a[2,6]-1;
          if letter ='æ' then a[2,7]:=a[2,7]-1;
          end;
          if x=3 then begin
          if letter ='à' then a[3,1]:=a[3,1]-1;
          if letter ='á' then a[3,2]:=a[3,2]-1;
          if letter ='â' then a[3,3]:=a[3,3]-1;
          if letter ='ã' then a[3,4]:=a[3,4]-1;
          if letter ='ä' then a[3,5]:=a[3,5]-1;
          if letter ='å' then a[3,6]:=a[3,6]-1;
          if letter ='æ' then a[3,7]:=a[3,7]-1;
          end;
          if x=4 then begin
          if letter ='à' then a[4,1]:=a[4,1]-1;
          if letter ='á' then a[4,2]:=a[4,2]-1;
          if letter ='â' then a[4,3]:=a[4,3]-1;
          if letter ='ã' then a[4,4]:=a[4,4]-1;
          if letter ='ä' then a[4,5]:=a[4,5]-1;
          if letter ='å' then a[4,6]:=a[4,6]-1;
          if letter ='æ' then a[4,7]:=a[4,7]-1;
          end;
          if x=5 then begin
          if letter ='à' then a[5,1]:=a[5,1]-1;
          if letter ='á' then a[5,2]:=a[5,2]-1;
          if letter ='â' then a[5,3]:=a[5,3]-1;
          if letter ='ã' then a[5,4]:=a[5,4]-1;
          if letter ='ä' then a[5,5]:=a[5,5]-1;
          if letter ='å' then a[5,6]:=a[5,6]-1;
          if letter ='æ' then a[5,7]:=a[5,7]-1;
          end;
          if x=6 then begin
          if letter ='à' then a[6,1]:=a[6,1]-1;
          if letter ='á' then a[6,2]:=a[6,2]-1;
          if letter ='â' then a[6,3]:=a[6,3]-1;
          if letter ='ã' then a[6,4]:=a[6,4]-1;
          if letter ='ä' then a[6,5]:=a[6,5]-1;
          if letter ='å' then a[6,6]:=a[6,6]-1;
          if letter ='æ' then a[6,7]:=a[6,7]-1;
          end;
          if x=7 then begin
          if letter ='à' then a[7,1]:=a[7,1]-1;
          if letter ='á' then a[7,2]:=a[7,2]-1;
          if letter ='â' then a[7,3]:=a[7,3]-1;
          if letter ='ã' then a[7,4]:=a[7,4]-1;
          if letter ='ä' then a[7,5]:=a[7,5]-1;
          if letter ='å' then a[7,6]:=a[7,6]-1;
          if letter ='æ' then a[7,7]:=a[7,7]-1;
          end;
          if x=8 then begin
          if letter ='à' then a[8,1]:=a[8,1]-1;
          if letter ='á' then a[8,2]:=a[8,2]-1;
          if letter ='â' then a[8,3]:=a[8,3]-1;
          if letter ='ã' then a[8,4]:=a[8,4]-1;
          if letter ='ä' then a[8,5]:=a[8,5]-1;
          if letter ='å' then a[8,6]:=a[8,6]-1;
          if letter ='æ' then a[8,7]:=a[8,7]-1;
          end;
          if x=9 then begin
          if letter ='à' then a[9,1]:=a[9,1]-1;
          if letter ='á' then a[9,2]:=a[9,2]-1;
          if letter ='â' then a[9,3]:=a[9,3]-1;
          if letter ='ã' then a[9,4]:=a[9,4]-1;
          if letter ='ä' then a[9,5]:=a[9,5]-1;
          if letter ='å' then a[9,6]:=a[9,6]-1;
          if letter ='æ' then a[9,7]:=a[9,7]-1;
          end;
          if x=10 then begin
          if letter ='à' then a[10,1]:=a[10,1]-1;
          if letter ='á' then a[10,2]:=a[10,2]-1;
          if letter ='â' then a[10,3]:=a[10,3]-1;
          if letter ='ã' then a[10,4]:=a[10,4]-1;
          if letter ='ä' then a[10,5]:=a[10,5]-1;
          if letter ='å' then a[10,6]:=a[10,6]-1;
          if letter ='æ' then a[10,7]:=a[10,7]-1;
          end;
          if x=11 then begin
          if letter ='à' then a[11,1]:=a[11,1]-1;
          if letter ='á' then a[11,2]:=a[11,2]-1;
          if letter ='â' then a[11,3]:=a[11,3]-1;
          if letter ='ã' then a[11,4]:=a[11,4]-1;
          if letter ='ä' then a[11,5]:=a[11,5]-1;
          if letter ='å' then a[11,6]:=a[11,6]-1;
          if letter ='æ' then a[11,7]:=a[11,7]-1;
          end;
       END;
while pos(' ',s)<>0 do
  delete (s,1,pos(' ',s));
    yx:=copy (s,1,length(s)-1);
    letter:=copy (s,length(s),1);
    val (yx,x,osh);
    if osh=0 then
      Begin
        if x=1 then begin
          if letter ='à' then inc (a[1,1]);
          if letter ='á' then inc (a[1,2]);
          if letter ='â' then inc (a[1,3]);
          if letter ='ã' then inc (a[1,4]);
          if letter ='ä' then inc (a[1,5]);
          if letter ='å' then inc (a[1,6]);
          if letter ='æ' then inc (a[1,7]);
          end;
       if x=2 then begin
          if letter ='à' then inc (a[2,1]);
          if letter ='á' then inc (a[2,2]);
          if letter ='â' then inc (a[2,3]);
          if letter ='ã' then inc (a[2,4]);
          if letter ='ä' then inc (a[2,5]);
          if letter ='å' then inc (a[2,6]);
          if letter ='æ' then inc (a[2,7]);
          end;
          if x=3 then begin
          if letter ='à' then inc (a[3,1]);
          if letter ='á' then inc (a[3,2]);
          if letter ='â' then inc (a[3,3]);
          if letter ='ã' then inc (a[3,4]);
          if letter ='ä' then inc (a[3,5]);
          if letter ='å' then inc (a[3,6]);
          if letter ='æ' then inc (a[3,7]);
          end;
          if x=4 then begin
          if letter ='à' then inc (a[4,1]);
          if letter ='á' then inc (a[4,2]);
          if letter ='â' then inc (a[4,3]);
          if letter ='ã' then inc (a[4,4]);
          if letter ='ä' then inc (a[4,5]);
          if letter ='å' then inc (a[4,6]);
          if letter ='æ' then inc (a[4,7]);
          end;
          if x=5 then begin
          if letter ='à' then inc (a[5,1]);
          if letter ='á' then inc (a[5,2]);
          if letter ='â' then inc (a[5,3]);
          if letter ='ã' then inc (a[5,4]);
          if letter ='ä' then inc (a[5,5]);
          if letter ='å' then inc (a[5,6]);
          if letter ='æ' then inc (a[5,7]);
          end;
          if x=6 then begin
          if letter ='à' then inc (a[6,1]);
          if letter ='á' then inc (a[6,2]);
          if letter ='â' then inc (a[6,3]);
          if letter ='ã' then inc (a[6,4]);
          if letter ='ä' then inc (a[6,5]);
          if letter ='å' then inc (a[6,6]);
          if letter ='æ' then inc (a[6,7]);
          end;
          if x=7 then begin
          if letter ='à' then inc (a[7,1]);
          if letter ='á' then inc (a[7,2]);
          if letter ='â' then inc (a[7,3]);
          if letter ='ã' then inc (a[7,4]);
          if letter ='ä' then inc (a[7,5]);
          if letter ='å' then inc (a[7,6]);
          if letter ='æ' then inc (a[7,7]);
          end;
          if x=8 then begin
          if letter ='à' then inc (a[8,1]);
          if letter ='á' then inc (a[8,2]);
          if letter ='â' then inc (a[8,3]);
          if letter ='ã' then inc (a[8,4]);
          if letter ='ä' then inc (a[8,5]);
          if letter ='å' then inc (a[8,6]);
          if letter ='æ' then inc (a[8,7]);
          end;
          if x=9 then begin
          if letter ='à' then inc (a[9,1]);
          if letter ='á' then inc (a[9,2]);
          if letter ='â' then inc (a[9,3]);
          if letter ='ã' then inc (a[9,4]);
          if letter ='ä' then inc (a[9,5]);
          if letter ='å' then inc (a[9,6]);
          if letter ='æ' then inc (a[9,7]);
          end;
       if x=10 then begin
          if letter ='à' then inc (a[10,1]);
          if letter ='á' then inc (a[10,2]);
          if letter ='â' then inc (a[10,3]);
          if letter ='ã' then inc (a[10,4]);
          if letter ='ä' then inc (a[10,5]);
          if letter ='å' then inc (a[10,6]);
          if letter ='æ' then inc (a[10,7]);
          end;
         if x=11 then begin
          if letter ='à' then inc (a[11,1]);
          if letter ='á' then inc (a[11,2]);
          if letter ='â' then inc (a[11,3]);
          if letter ='ã' then inc (a[11,4]);
          if letter ='ä' then inc (a[11,5]);
          if letter ='å' then inc (a[11,6]);
          if letter ='æ' then inc (a[11,7]);
          end;
      End;
end;
for i:= 1 to 11 do
  for j:=1 to 7 do
    if a[i,j]>0 then begin
    if j=1 then write (f2,i,'A',' ');
    if j=2 then write (f2,i,'Á',' ');
    if j=3 then write (f2,i,'Â',' ');
    if j=4 then write (f2,i,'Ã',' ');
    if j=5 then write (f2,i,'Ä',' ');
    if j=6 then write (f2,i,'Å',' ');
    if j=7 then write (f2,i,'Æ',' ');
    end;
    close (f1); close (f2);
    end.
Считано нормально, действия нормальны, а с выводом проблема - ошибка в превышении по времени. Что не так?
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
20.02.2013, 17:31
Ответы с готовыми решениями:

Задача на перебор вариантов. Задача Л.Эйлера. Про чиновника
Задача Л.Эйлера. Некий чиновник купил лошадей и быков на сумму 1770 талеров. За каждую лошадь он...

Задача про взлом кода из книги Эрика Фримена про основы javascript в конце 5 главы.
читаю книгу Эрика Фримена про основы javascript.В конце 5 главы есть задачка про взлом кода.Никак...

Задача про IP
Простите что не совсем в тему , но у меня ответ 97.15.81.53/15 , но говорят это неправильно ...

Задача про карты
Евгений продолжает набирать опыт в разработке и теперь пишет компьютерную игру в жанре «Квест»,...

3
Почетный модератор
64300 / 47595 / 32743
Регистрация: 18.05.2008
Сообщений: 115,181
20.02.2013, 19:36 2
А писать не надоело это?
Можно же индексы в матрице привязать к буквам алфавита.
Кстати на каком Паскале пишем, а то АВС понимает русский шрифт и индексы одни, а Турбо и Фрее не понимают и индексы другие.
0
0 / 0 / 0
Регистрация: 20.02.2013
Сообщений: 2
20.02.2013, 19:44  [ТС] 3
Цитата Сообщение от Puporev Посмотреть сообщение
А писать не надоело это?
Можно же индексы в матрице привязать к буквам алфавита.
Кстати на каком Паскале пишем, а то АВС понимает русский шрифт и индексы одни, а Турбо и Фрее не понимают и индексы другие.
Надоело. Язык Паскаль ABC
0
Почетный модератор
64300 / 47595 / 32743
Регистрация: 18.05.2008
Сообщений: 115,181
21.02.2013, 11:41 4
Pascal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
uses crt;
const cf=['0'..'9'];
      m=11;
      k=7;
var f1,f2:text;
    a:array [1..m,1..k] of integer;
    s,s1:string;
    i,j,n,x,y,c:integer;
begin
assign (f1,'in.txt'); reset (f1);
assign (f2,'out.txt'); rewrite (f2);
readln (f1,n);
for i:=1 to m do
for j:=1 to k do
a[i,j]:=0;
for i:=1 to n do
 begin
  readln (f1,s);
  s1:=''; //первый номер от 1 до 11
  j:=1;
  while s[j] in cf do
   begin
    s1:=s1+s[j];
    j:=j+1;
   end;
  val(s1,x,c);
  y:=ord(s[j])-223; //первая буква от а до ж
  inc(a[x,y]);
  y:=ord(s[length(s)])-223;//вторая буква(в конце строки)
  s1:=''; //второй номер
  j:=length(s)-1;
  while s[j] in cf do
   begin
    s1:=s[j]+s1;
    j:=j-1;
   end;
  val(s1,x,c);
  dec(a[x,y]);
 end;
close(f1);
for i:=1 to m do
for j:=1 to k do
if a[i,j]>0 then writeln(f2,i,chr(j+223));
close(f2);
write('Результат записан в файл out.txt')
end.
0
21.02.2013, 11:41
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
21.02.2013, 11:41
Помогаю со студенческими работами здесь

задача про резервуар
Внутреннюю поверхность резервуара емкостью 4 м3 с квадратным основанием, открытого сверху, нужно...

Задача про телеграмм
Задача 01 По мнению правоохранительных органов, Telegram обязан хранить ключи шифрования от всей...

Задача про автомобиль
Вообщем, задача одна не из лёгких, во всяком случае для меня. Для тех, кто любит поломать голову и...

Задача про бензозаправку
Число грузовых автомобилей проезжающих по шоссе на котором стоит бензоколонка относится к числу...

Задача про квадрат
В квадрат со стороной L бросаются наудачу независимо друг от друга 2 квадрата со стороной l&lt;L/2....

Задача про термосумку
Задача))) Есть кулбокс - контейнер с известными параметрами: длинна, ширина, высота, толщина...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
4
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru