§ 17. Масівы і структуры як параметры функцый

Практыкаванні

    

1.  Для задачы з прыкладу 17.5 выканайце пералічаныя заданні.

1. Пералічыце сітуацыі, якія належаць да «астатніх выпадкаў» ва ўмове задачы.
2. Змяніце праграму так, каб для «астатніх выпадкаў» выводзіліся значэнні  begin mathsize 16px style min open parentheses straight b subscript 0 space... space straight b subscript straight m space minus space 1 end subscript close parentheses end style і  max open parentheses straight b subscript 0 space... space straight b subscript straight m space minus space 1 end subscript close parentheses. 

2.  Дадзены натуральныя n, m, k цэлыя a0, ..., an-1, b0, ..., bm-1, c0, ..., ck-1, атрымаць:

1. t space equals space open curly brackets table attributes columnalign left end attributes row cell min open parentheses straight a subscript 0... straight a subscript straight n space minus space 1 end subscript close parentheses space plus space max open parentheses straight b subscript 0... straight b subscript straight m space minus space 1 end subscript close parentheses comma space space space калі space space space min open parentheses straight с subscript 0... straight с subscript straight k space minus space 1 end subscript close parentheses less than negative 100 end cell row cell min open parentheses straight a subscript 0... straight a subscript straight n space minus space 1 end subscript close parentheses space plus space min open parentheses straight b subscript 0... straight b subscript straight m space minus space 1 end subscript close parentheses comma space space space калі space space space space min open parentheses straight с subscript 0... straight с subscript straight k space minus space 1 end subscript close parentheses greater than 100 end cell row cell m a x open parentheses straight a subscript 0... straight a subscript straight n space minus space 1 end subscript close parentheses space plus space max open parentheses straight b subscript 0... straight b subscript straight m space minus space 1 end subscript close parentheses comma space space space straight у space астатніх space выпадках end cell end table close

2. t space equals space open curly brackets table attributes columnalign left end attributes row cell min open parentheses straight a subscript 0... straight a subscript straight n space minus space 1 end subscript close parentheses space plus space max open parentheses straight b subscript 0... straight b subscript straight m space minus space 1 end subscript close parentheses comma space space space калі space space space space min open parentheses straight с subscript 0... straight с subscript straight k space minus space 1 end subscript close parentheses space asterisk times space max open parentheses straight c subscript 0... straight c subscript straight k space minus space 1 end subscript close parentheses space greater than space 0 end cell row cell max open parentheses straight c subscript 0... straight c subscript straight k space minus space 1 end subscript close parentheses space plus space min open parentheses straight b subscript 0... straight b subscript straight m space minus space 1 end subscript close parentheses comma space space калі space space space space min open parentheses straight с subscript 0... straight с subscript straight k space minus space 1 end subscript close parentheses space asterisk times space max open parentheses straight c subscript 0... straight c subscript straight k space minus space 1 end subscript close parentheses space less than negative 100 end cell row cell min open parentheses straight c subscript 0... straight c subscript straight k space minus space 1 end subscript close parentheses space plus space max open parentheses straight a subscript 0... straight a subscript straight n space minus space 1 end subscript close parentheses comma space space space straight у space астатніх space выпадках end cell end table close

3. t space equals space open curly brackets table attributes columnalign left end attributes row cell min open parentheses straight a subscript 0... straight a subscript straight n space minus space 1 end subscript close parentheses space plus space max open parentheses straight b subscript 0... straight b subscript straight m space minus space 1 end subscript close parentheses comma space space space калі space space space space min open parentheses straight с subscript 0... straight с subscript straight k space minus space 1 end subscript close parentheses space asterisk times space max open parentheses straight c subscript 0... straight c subscript straight k space minus space 1 end subscript close parentheses space less than negative 10 end cell row cell max open parentheses straight c subscript 0... straight c subscript straight k space minus space 1 end subscript close parentheses space plus space min open parentheses straight b subscript 0... straight b subscript straight m space minus space 1 end subscript close parentheses comma space space space калі space space space minus 10 space less or equal than space min open parentheses straight с subscript 0... straight с subscript straight k space minus space 1 end subscript close parentheses space asterisk times space max open parentheses straight c subscript 0... straight c subscript straight k space minus space 1 end subscript close parentheses space less than 0 end cell row cell max open parentheses straight a subscript 0... straight a subscript straight n space minus space 1 end subscript close parentheses space plus space max open parentheses straight b subscript 0... straight b subscript straight m space minus space 1 end subscript close parentheses comma space space калі space space space 0 space less or equal than space min open parentheses straight с subscript 0... straight с subscript straight k space minus space 1 end subscript close parentheses space asterisk times space max open parentheses straight c subscript 0... straight c subscript straight k space minus space 1 end subscript close parentheses space less than 10 end cell row cell min open parentheses straight c subscript 0... straight c subscript straight k space minus space 1 end subscript close parentheses space plus space max open parentheses straight a subscript 0... straight a subscript straight n space minus space 1 end subscript close parentheses comma space space space straight у space астатніх space выпадках end cell end table close

3.  Дадзены натуральны n і цэлыя x0, ..., xn – 1, y0, ..., yn – 1. Атрымаць:

1. t space equals space open curly brackets table attributes columnalign left end attributes row cell sum from straight i space equals space 0 to straight n space minus 1 of space straight x subscript straight i superscript 2 comma space text пры end text space sum from straight i space equals space 0 to straight n space minus 1 of space straight x subscript straight i space straight y subscript straight i space greater than 0 end cell row cell sum from straight i space equals space 0 to straight n space minus 1 of space straight y subscript straight i superscript 2 comma space інакш end cell end table close

2. t space equals space open curly brackets table attributes columnalign left end attributes row cell sum from straight i space equals space 0 to straight n space minus 1 of space straight x subscript straight i superscript 2 space minus space straight y subscript straight i superscript 2 comma space пры space space sum from straight i space equals space 0 to straight n space minus 1 of space straight x subscript straight i superscript 2 space minus space sum from straight i space equals space 0 to straight n space minus 1 of space straight y subscript straight i superscript 2 space less than space 0 end cell row cell sum from straight i space equals space 0 to straight n space minus 1 of space straight x subscript straight i straight y subscript straight i comma space пры space space sum from straight i space equals space 0 to straight n space minus 1 of space straight x subscript straight i superscript 2 space minus space sum from straight i space equals space 0 to straight n space minus 1 of space straight y subscript straight i superscript 2 space greater than space 10 end cell row cell sum from straight i space equals space 0 to straight n space minus 1 of space straight x subscript straight i superscript 2 space straight y subscript straight i superscript 2 comma space space straight у space астатніх space выпадках end cell end table close

Запіс  begin mathsize 16px style begin inline style sum from straight i space equals space 0 to straight n space minus 1 of end style space straight x subscript straight i end style абазначае суму ўсіх xi  пры змяненні  i от 0 да n – 1: x0 + x1 + ... + xn – 1.

4. Зададзены двухмерны масіў a з m радкоў і n слупкоў. Атрымаць лінейны масіў b, у якім b[i] — это:

  1. Колькасць дадатных элементаў i-га радка масіву a.
  2. Цэлая частка сярэдняга арыфметычнага i-га радка масіву a.
  3. Мінімальны элемент i-га радка масіву a.
  4. Колькасць лікаў, модуль якіх роўны модулю максімальнага элемента i-га радка масіву a.
  5. Колькасць лікаў, якія пры дзяленні на 3 і на 5 даюць аднолькавыя астачы.
  6. Лік, які сустракаецца ў i-м радку масіву a часцей іншых лікаў. Калі такіх лікаў некалькі, то ўзяць лік з меншым нумарам у радку.
  7. Рэалізаваць пункты 1—6 для слупкоў. Для гэтага транспаніраваць матрыцу (гл. прыклад 15.13).

5.  Зададзены двухмерны масіў a з m радкоў і n слупкоў.

  1. Вывесці нумары радкоў, якія змяшчаюць мінімальны элемент двухмернага масіву.
  2. Вывесці нумары радкоў, у якіх ёсць роўныя элементы. Калі такіх радкоў няма, то вывесці адпаведнае паведамленне.
  3. Вывесці нумары радкоў, у якіх усе элементы розныя. Калі такіх радкоў няма, то вывесці адпаведнае паведамленне.
  4. Вывесці нумары радкоў, сумы элементаў у якіх роўныя. Вывад ажыццявіць у выглядзе табліцы.

Прыклад

Тлумачэнне

0:

1: 2, 3

2: 3

3:

4: 5

5:

Сума элементаў першага радка роўна суме элементаў 2-га і 3-га радкоў, сума элементаў 2-га радка роўна суме элементаў 3-га радка.

Сума элементаў 4-га радка роўна суме элементаў 5-га радка.

Для радкоў 0 і 3 няма радкоў з роўнымі ім сумамі.

Для кожнага радка правяряюцца толькі радкі з  нумарамі, якія большыя, чым нумар бягучага радка.

5. Рэалізаваць пункты 1—4 для слупкоў. Для гэтага транспаніраваць матрыцу (гл. прыклад 15.13).

6.  Унясіце змяненні ў праграму прыкладу 17.8 так, каб праграма карэктна апрацоўвала назвы гарадоў, якія складаюцца больш чым з аднаго слова (напрыклад, Старыя Дарогі ці Ніжні Ноўгарад).

7.  Стварыць тэкставы файл апісанай ніжэй структуры. У першым радку ў тэкставым файле запісаць колькасць даных. Колькасць даных павялічыць да 10, падабраўшы патрэбную інфармацыю. Вывесці ў тэкставы файл з імем otchet.txt даныя, якія задавальняюць пералічаныя ўмовы.

1. У файле захоўваюцца: назва краінны[1], сталіца, плошча (тыс. км2) і колькасць насельніцтва (млн чал.):

Беларусь     Мінск           208        9.41

Расія        Масква          17075      143.3

ЗША          Вашынгтон       9373       310.2

Канада       Атава           9985       34.2

Францыя      Парыж           547        65.4

І г.д.

Знайсці колькасць краін з насельніцтвам <=50 млн чал. і тыя краіны, назва сталіцы якіх складаецца з k (уводзіцца з клавіятуры) літар.

2. У файле захоўваюцца: назва вытворцаў пральнай машыны, яе мадэль, магутнасць і максімальная загрузка бялізны (кг).

Samsung     WW65K52E69S      2400    6.5

Bosch       WLT24440OE       2300    7

Haier       HW70-BP12758S    1900    7

LG          F12M7NDS0        1700    6

И т.д.

Знайсці колькасць пральных машын з магутнасцю >2000 і назвы вытворцаў, у мадэль якіх уваходзіць літара «х» (значэнне «х» уводзіцца з клавіятуры)

3. У файле захоўваюцца: назва возера[2], вобласць, у якой яно размешчана; яго аб’ём (млн м3), плошча (км2), максімальная глыбіня (м) і празрыстасць (м).

Нарач       Мінская         710       79.6     24.8     7.4

Снуды       Вшцебская       107       22       16.5     6.6

Рычы        Віцебская       131.5     12.9     51.9     5.5

Свіцязь     Гродненская     7.76      25.2     15       5.2

І г.д.

Знайсці самае глыбокае і самае празрыстае возера (вывесці назву і месцазнаходжанне), а таксама назвы тых азёр, якія знаходзяцца ў паказанай вобласці (увесці з клавіятуры).



[1] http://ostranah.ru/ – геаграфічны даведнік «Аб краінах» (дата доступу: 20.06.2020).