Skip to content

Instantly share code, notes, and snippets.

@kirilltobola
Last active November 28, 2021 15:43
Show Gist options
  • Save kirilltobola/d15124eb5a8bef29fbc351697e4789d6 to your computer and use it in GitHub Desktop.
Save kirilltobola/d15124eb5a8bef29fbc351697e4789d6 to your computer and use it in GitHub Desktop.
Functoins (lab 7)
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
vector<double> arr = {1.9, 1.32, 1.0, 5.8, 5.1, 12.6, 13.2, 13.1};
sort(
arr.begin(),
arr.end(),
[] (const double &x, const double &y) {
if ((int) x > (int) y) {
return false;
} else if ((int) x < (int) y) {
return true;
} else if ((int) x - x > (int) y - y) {
return false;
} else {
return true;
}
}
);
for (auto i: arr) {
cout << i << endl;
}
return 0;
}
import java.util.Arrays;
class HelloWorld {
public static void main(String[] args) {
Double arr[] = {1.9, 1.32, 1.0, 5.8, 5.1, 12.6, 13.2, 13.1};
Arrays.sort(
arr,
(x, y) -> {
if (Math.floor(x) > Math.floor(y)) {
return 1;
} else if (Math.floor(x) < Math.floor(y)) {
return -1;
} else {
if (x - Math.floor(x) > y - Math.floor(y)) {
return -1;
} else if (x - Math.floor(x) < y - Math.floor(y)) {
return 1;
} else {
return 0;
}
}
}
);
System.out.println(
Arrays.toString(arr)
);
}
}
arr: list = [1.9, 1.32, 1.0, 5.1, 5.8, 12.6, 13.2, 13.1]
res: list = sorted(arr, key=lambda x: (int(x), -x + int(x)))
print(res)
#include <iostream>
using namespace std;
void dswap(double *x, double *y) {
double temp = *x;
*x = *y;
*y = temp;
}
int main() {
double x = 1.5, y = 3.1;
dswap(&x, &y);
cout << x << ' ' << y << endl;
return 0;
}
#include <iostream>
void killer() {
return killer();
}
int main() {
killer();
return 0;
}
def some_func():
n: int = 0
def nested_func():
nonlocal n
n += 1
return n
return nested_func
nested = some_func()
for i in range(10):
print(nested(), end='\n')
class HelloWorld {
public static int id = 0;
public static void main(String[] args) {
HelloWorld.id += 1;
System.out.print(HelloWorld.id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment