Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <iostream>
using namespace std;
bool is_int(string number) {
bool after_dot = false;
for (char c : number) {
if (after_dot and c != '0') {
return false;
} else if (c == '.') {
after_dot = true;
}
}
return true;
}
int main(void) {
string number;
cin >> number;
cout << (is_int(number) ? "OK" : "NOT INTEGER") << endl;
return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;
string as_bin_string_leading_zero(int number) {
string binword;
while (number) {
binword.append(number % 2 ? "1" : "0");
number /= 2;
}
while (binword.size() % 8) {
binword.append("0");
}
reverse(binword.begin(), binword.end());
return binword;
}
int main(void) {
int number;
cin >> number;
string binword = as_bin_string_leading_zero(number);
for (int i=0; i<binword.size(); i+=8) {
cout << binword.substr(i, i+8) << " ";
}
cout << endl;
return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;
int publication[100020];
int main(void) {
int n;
cin >> n;
for (int i=0; i<n; i++) {
cin >> publication[i];
}
sort(publication, publication+n);
for (int i=0; i<n; i++) {
cout << publication[i] << " ";
}
cout << endl;
return 0;
}
#include <iostream>
using namespace std;
long pivot[3];
long matrix[3][3];
long gcd(long a, long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
void swap_row(int i, int j) {
for (int k=0; k<3; k++) {
swap(matrix[i][k], matrix[j][k]);
}
}
void sub_row(int i, int j) {
for (int k=0; k<3; k++) {
matrix[i][k] -= matrix[j][k];
}
}
void mul_row_scalar(int i, long n) {
for (int k=0; k<3; k++) {
matrix[i][k] *= n;
}
}
void make_lead_rows(int i) {
for (int j=i+1; j<3; j++) {
if (matrix[i][i] == 0 and matrix[j][i] != 0) {
swap_row(i, j);
}
}
}
void eliminate_rows(int i) {
for (int j=i+1; j<3; j++) {
if (matrix[j][i] != 0) {
long g = gcd(matrix[i][i], matrix[j][i]);
long jg = matrix[j][i] / g;
long ig = matrix[i][i] / g;
mul_row_scalar(i, jg);
mul_row_scalar(j, ig);
sub_row(j, i);
}
}
}
bool is_col_zero(int i) {
for (int k=i; k<3; k++) {
if (matrix[i][k] != 0) {
return false;
}
}
return true;
}
bool is_plane(void) {
for (int i=0; i<3; i++) {
if (is_col_zero(i)) {
return true;
}
make_lead_rows(i);
eliminate_rows(i);
}
return false;
}
int main(void) {
int t;
cin >> t;
for (int i=0; i<t; i++) {
for (int k=0; k<3; k++) {
cin >> pivot[k];
}
for (int j=0; j<3; j++) {
for (int k=0; k<3; k++) {
cin >> matrix[j][k];
matrix[j][k] -= pivot[k];
}
}
cout << (is_plane() ? "YES" : "NO") << endl;
}
return 0;
}
#include <iostream>
using namespace std;
long fibs[90];
void init_fibs(void) {
fibs[0] = -1;
fibs[1] = 1;
fibs[2] = 1;
for (int i=3; i<90; i++) {
fibs[i] = fibs[i-1] + fibs[i-2];
}
}
char find_fib_char(int n, long k) {
if (n == 1) {
return 'A';
}
if (n == 2) {
return 'B';
}
if (k <= fibs[n-2]) {
return find_fib_char(n-2, k);
} else {
return find_fib_char(n-1, k-fibs[n-2]);
}
}
int main(void) {
init_fibs();
int t;
cin >> t;
for (int i=0; i<t; i++) {
int n;
long k;
cin >> n >> k;
cout << find_fib_char(n, k) << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment