Skip to content

Commit

Permalink
Added zad 4, 8, 10, 11, 12
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelkubek committed Nov 18, 2023
1 parent f75e246 commit 703d8f3
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,22 @@ _WDP\* MIM UW_

- [zad. 3.]
- [zad_3](./src/cw6/zad3/zad3_sadzawka.cpp): autor: @pixelkubek (C++) :white_check_mark:
- [zad. 4.]
- [zad_4](./src/cw6/zad4/zad4.cpp): autor: @pixelkubek (C++) :white_check_mark:
- [zad. 5.]
- [katastrofy](./src/cw6/zad5/katastrofy.cpp) (C++) :white_check_mark::microscope:
- [zad. 7.]
- [zad_7](./src/cw6/zad7/zad7_skyline.cpp): autor: @pixelkubek (C++) :white_check_mark:
- [zad. 8.]
- [zad_8](./src/cw6/zad8/zad8.cpp): autor: @pixelkubek (C++) :white_check_mark:
- [zad. 9.]
- [zad_9](./src/cw6/zad9/zad9_Zeckendorf.c): autor: @pixelkubek (C) :white_check_mark:
- [zad. 10.]
- [zad_10](./src/cw6/zad10/zad10.cpp): autor: @pixelkubek (C++) :white_check_mark:
- [zad. 11.]
- [zad_11](./src/cw6/zad11/zad11.cpp): autor: @pixelkubek (C++) :white_check_mark:
- [zad. 12.]
- [zad_12](./src/cw6/zad12/zad12.cpp): autor: @pixelkubek (C++) :white_check_mark:

## Kolokwia

Expand Down
27 changes: 27 additions & 0 deletions src/cw6/zad10/zad10.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include<stack>
#include<stdio.h>

using namespace std;

int nawiasy(char arr[]){
int wynik = 0;
stack<int> s;
s.push(-1);

for(int i = 0; arr[i]; i++){
if(arr[i] == '(')
s.push(i);

if(arr[i] == ')' && s.top() != -1 && arr[s.top()] == '('){
s.pop();
wynik = max(wynik, i - s.top());
}
}
return wynik;
}

int main(){
char string[] = "()))(()())((((()()())()";
printf("%i\n", nawiasy(string));
return 0;
}
45 changes: 45 additions & 0 deletions src/cw6/zad11/zad11.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include<queue>
#include<deque>
#include<stdio.h>

using namespace std;

int dlugosc(int a[], int n){
if(n == 0)
return 0;

queue<int> q;
deque<int> minima; //zakladam, ze deque zostaly zaimplementowane w zad2
int dl = 1, wynik = 0;
q.push(0);
minima.push_back(0);

for(int i = 1; i < n; i++){
while(!minima.empty() && a[minima.back()] >= a[i]){
minima.pop_back();
}
minima.push_back(i);

while(dl >= a[minima.front()]){
if(minima.front() == q.front()){ //usuwam minimum
minima.pop_front();
}
q.pop();
dl--;
}

if(dl < a[minima.front()]){
dl++;
wynik = max(wynik, dl);
q.push(i);
}
}

return wynik;
}

int main(){
int n = 11, t[] = {1, 8, 6, 5, 6, 1, 7, 8, 6, 3, 4};
printf("%i\n", dlugosc(t, n));
return 0;
}
52 changes: 52 additions & 0 deletions src/cw6/zad12/zad12.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include<queue>
#include<stdio.h>

using namespace std;

int slowa(char s[]){
queue<char> nastSlowo;
queue<char> q;
int wynik = 1;
q.push('a');
q.push('|');
q.push('b');

for(int i = 0; s[i]; i++){
if(s[i] == q.front()){
nastSlowo.push(q.front());
q.pop();

if(q.front() == '|'){
wynik++;
q.pop();
q.push('|');

//przepisanie nastSlowo
nastSlowo.push('|');
while(nastSlowo.front() != '|'){
q.push(nastSlowo.front());
nastSlowo.push(nastSlowo.front());
nastSlowo.pop();
}
nastSlowo.pop();
}
}
}

bool byloB = false;
if(wynik == 1)
for(int i = 0; s[i]; i++)
if(s[i] == 'b')
byloB = true;

if(wynik > 1) return wynik;
else if(byloB) return 1;
else return 0;

}

int main(){
char s[] = "abzzabaabacab";
printf("%i\n", slowa(s));
return 0;
}
40 changes: 40 additions & 0 deletions src/cw6/zad4/zad4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include<stack>
#include<stdio.h>

using namespace std;

typedef enum pora {Wiosna, Lato, Jesień, Zima} pora;

int pory(int size, pora arr[]){
int wynik = -1, najdalszaPora = -1;
stack<int> s;
for(int i = 0; i < size; i++){
if(arr[i] == najdalszaPora + 1)
najdalszaPora++;

if(najdalszaPora == 3){ //zima i wszystko przed w odpowiedniej kolejnosci
while(arr[s.top()] != Jesień){
s.pop();
}
while(arr[s.top()] != Lato){
s.pop();
}
while(arr[s.top()] != Wiosna){
s.pop();
}

wynik = max(wynik, i - s.top() + 1);
s.pop();
najdalszaPora = -1;
} else {
s.push(i);
}
}
return wynik;
}

int main(){
pora arr[10] = {Wiosna, Wiosna, Jesień, Zima, Lato, Wiosna, Jesień, Zima, Zima, Zima};
printf("%i\n", pory(10, arr));
return 0;
}
29 changes: 29 additions & 0 deletions src/cw6/zad8/zad8.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include<stack>
#include<stdio.h>

using namespace std;

int roznica(int t[], int n){
int wynik = 0;
stack<int> s;
for(int i = 0; i < n; i++){
while(!s.empty() && t[s.top()] <= t[i]){
s.pop();
}
if(!s.empty()){
wynik = max(wynik, i - s.top() - 1);
} else {
wynik = i - 1;
}

s.push(i);
}

return wynik;
}

int main(){
int n = 7, t[] = {6, 4, 3, 4, 5, 2, 3};
printf("%i\n", roznica(t, n));
return 0;
}

0 comments on commit 703d8f3

Please sign in to comment.