Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- long long ans = 0;
- int convert(char* s) {
- int result = 0;
- int scr = 0;
- while (*s != '\0') {
- s++;
- scr++;
- }
- s--;
- for (int digit = 1, ten = 1; digit <= scr; digit++) {
- int l = '0';
- result += (*s - l) * ten;
- ten *= 10;
- s--;
- }
- return result;
- }
- void Permutation(int k, long long product, int* sizes, int** array, int n) { //n - число массивов
- if (k == n) { //тк 0-нумерация
- ans += product;
- return;
- }
- for (int i = 0; i < sizes[k]; i++) {
- if (array[k][i] == 0) {
- continue;
- }
- product *= array[k][i];
- Permutation(k + 1, product, sizes, array, n);
- product /= array[k][i];
- }
- }
- int main(int argc, char** argv) {
- int* sizes = new int[argc - 1];
- int** array = new int*[argc - 1];
- for (int i = 1; i < argc; i++) {
- sizes[i - 1] = convert(argv[i]); //заполнили массив длины массивов
- }
- for (int j = 0; j < argc - 1; j++) {
- array[j] = new int[sizes[j]];
- for (int el = 0; el < sizes[j]; el++) {
- int temp;
- std::cin >> temp;
- array[j][el] = temp;
- }
- }
- int n = argc - 1;
- Permutation(0, 1, sizes, array, n);
- std::cout << ans << "\n";
- for (int j = 0; j < argc - 1; j++) {
- delete[] array[j];
- }
- delete[] array;
- delete[] sizes;
- /* тк в cout с c-style строками всё ок
- int** p = new int* [argc - 1]; //указатель на массив массивов
- for (int i = 0; i < argc - 1; i++) {
- int size = *argv[i+1];
- p[i] = new int[size];
- for (int j = 0; j < *argv[i + 1]; j++) {
- std::cin >> p[i][j];
- }
- }
- for (int i = 0; i < argc - 1; i++) {
- delete[] p[i];
- }
- delete[] p; */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement