Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- struct List {
- int value;
- int line;
- int column;
- List* Next;
- List* Prev;
- };
- void MakeList(int N, int M, int n, int m, List** Head, List* Prev){
- if (m==M){
- m = 0;
- n++;
- }
- if (n==N)
- return;
- int tmp;
- cin >> tmp;
- if (tmp){
- (*Head) = (List*)malloc(sizeof(List));
- (*Head)->value = tmp;
- (*Head)->line = n;
- (*Head)->column = m;
- (*Head)->Prev = Prev;
- (*Head)->Next = NULL;
- MakeList(N, M, n, m+1, &((*Head)->Next), (*Head));
- } else
- MakeList(N, M, n, m+1, Head, Prev);
- }
- void PrintList (List *Head){
- if (Head!=NULL){
- if (Head->Prev){
- if (Head->Prev->column > Head->column)
- cout << endl;
- }
- cout << Head->value << ' ';
- PrintList(Head->Next);
- } else
- cout << endl;
- }
- void LAL (int *arr, List** Head){
- if (!(*Head))
- return;
- if (!arr[(*Head)->line])
- arr[(*Head)->line] = 1;
- arr[(*Head)->line] *= (*Head)->value;
- LAL (arr, &((*Head)->Next));
- }
- int main()
- {
- int N, M, i, *arr;
- cin >> N >> M;
- List* Lal;
- MakeList(N, M, 0, 0, &Lal, NULL);
- cout << "Your List:\n" ;
- PrintList(Lal);
- arr = (int*)calloc(N, sizeof(int));
- LAL(arr, &Lal);
- cout << "Product:\n";
- for (i = 0; i < N; i++)
- cout << arr[i] << ' ' ;
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement