Dodanie zadań do Lab1, Lab2, Lab3

This commit is contained in:
Kacper Nędzyński 2024-12-05 12:21:54 +01:00
commit b26ebf88a5
3 changed files with 69 additions and 0 deletions

15
Lab1/binarne.cpp Normal file
View File

@ -0,0 +1,15 @@
#include <iostream>
using namespace std;
int main() {
unsigned long long x;
cin>>x;
string binary;
while(x>0){
binary=(x%2==0 ? "0" : "1")+binary;
x/=2;
}
cout<<binary;
return 0;
}

39
Lab2/VIP.cpp Normal file
View File

@ -0,0 +1,39 @@
#include <iostream>
#include <string>
using namespace std;
const int MAX_N=500;
int checkVIP(int friendship[MAX_N][MAX_N], int n) {
int potentialVIP = 0;
for (int i = 1; i < n; i++) {
if (friendship[potentialVIP][i] == 1) {
potentialVIP = i;
}
}
for (int i = 0; i < n; i++) {
if (i != potentialVIP && (friendship[potentialVIP][i] == 1 || friendship[i][potentialVIP] == 0)) {
return -1;
}
}
return potentialVIP + 1;
}
int main(){
int x;//liczba zestawow
cin>>x;
while(x--){
int n;
cin>>n;
int friendship[MAX_N][MAX_N];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>friendship[i][j];
}
}
cout<<checkVIP(friendship,n)<<endl;
}
return 0;
}

15
Lab3/whilesuma.cpp Normal file
View File

@ -0,0 +1,15 @@
#include <iostream>
using namespace std;
int main(){
int n;
int suma=0;
do{
cin>>n;
suma= suma+n;
cout<<suma;
}while(suma<40);
return 0;
}