Дана программа. Определить результат выполнения. program N02; const A: array [1..6] of integer = (16,1,8,2,4,4); var i,k: integer; begin k:=0; for i:=2 to 6 do if A[i-1]>=A[i] then k:=k+1; write(k) end.
Логин занимает объём памяти равной = 20 * 5 бит = 100 бит (5 бит, т.к ) Аналогично с паролем, он занимает 15 * 4 бита = 60 бит памяти Для хранения результатов выбора пола достаточно одного бита ( всего два возможных варианта() - ж или м,). Итого одна учетная запись занимает: 100 + 60 +1 = 161 бит памяти. Но в условии сказано, что она кодируется минимально возможным целым! кол-вом байт, значит: 161/8 = 20,125 байт, округляем в большую сторону - 21 байт. Всего 30 записей: 21 * 30 = 630 байт. Значит верный ответ под номером 3)
#include <iostream> #include <string> #include <cstdlib> #include <algorithm> using namespace std; typedef unsigned short int USI;
int* fillArray(string name, int s); int maxArray(int[], int s); bool isPrime(int); void deleteAllEqualTo(int[], int s, int value); float averageOfPositive(int[], int s); void printArray(int[], int s);
bool sortByDescAbs(int i, int j) { return abs(i) > abs(j); }
int main() { setlocale(LC_ALL, "Russian"); USI n; cout << "n = "; cin >> n; int* z = fillArray("z", n); int max = maxArray(z, n); if ( isPrime(max) ) { deleteAllEqualTo(z, n, max); } float avg = averageOfPositive(z, n); cout << "среднее: " << avg << '\n'; sort(z, z + n, sortByDescAbs); cout << "z[" << n << "]: "; printArray(z, n); return 0; }
int* fillArray(string name, int s) { int array[s]; for (int i = 0; i < s; i++) { cout << name << "[" << i << "] = "; cin >> array[i]; } return array; }
int maxArray(int a[], int s) { int max = a[0]; for (int i = 1; i < s; i++) { if (a[i] > max) max = a[i]; } return max; }
bool isPrime(int n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; for (int i = 3; (i*i) <= n; i += 2) { if (n % i == 0 ) return false; } return true; }
void deleteAllEqualTo(int a[], int s, int value) { for (int i = 0; i < s; i++) { if (a[i] == value) a[i] = 0; } }
float averageOfPositive(int a[], int s) { unsigned int sum = 0, count = 0; for (int i = 0; i < s; i++) { if (a[i] > 0) { sum += a[i]; count++; } } return (sum / count); }
void printArray(int a[], int s) { for (int i = 0; i < s; i++) { cout << a[i] << ' '; } }
Аналогично с паролем, он занимает 15 * 4 бита = 60 бит памяти
Для хранения результатов выбора пола достаточно одного бита ( всего два возможных варианта() - ж или м,).
Итого одна учетная запись занимает: 100 + 60 +1 = 161 бит памяти.
Но в условии сказано, что она кодируется минимально возможным целым! кол-вом байт, значит: 161/8 = 20,125 байт, округляем в большую сторону - 21 байт.
Всего 30 записей: 21 * 30 = 630 байт.
Значит верный ответ под номером 3)