Created
August 24, 2019 20:07
-
-
Save neizod/5fa2a32d856be698a8b2e17429a4999b to your computer and use it in GitHub Desktop.
CCS sci-week (problem link http://tiny.cc/TaskSWP2019) (fb post https://www.facebook.com/ccscmu/photos/a.136488946945073/445643366029628/?type=3&theater)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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