Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- // int a[26][26] = {{NULL}};
- bool cflags[26];
- vector<map<char, int>> columns;
- vector<char> acids;
- vector<vector<long double>> matrix;
- vector<vector<long double>> S;
- vector<string> data;
- void strip(std::string &str ){
- if (!(str.length() == 0)) {
- auto w = std::string(" ") ;
- auto n = std::string("\n") ;
- auto r = std::string("\t") ;
- auto t = std::string("\r") ;
- auto v = std::string(1 ,str.front());
- while((v == w) or(v==t)or(v==r)or(v==n)) {str.erase(str.begin()) ;v = std::string(1 ,str.front()); }
- v = std::string(1 , str.back()) ;
- while((v ==w) or(v==t)or(v==r)or(v==n)) {str.erase(str.end() - 1 ) ;v = std::string(1 , str.back()) ;}
- }
- }
- void inc_columns(const string& s) {
- for (int i = 0; i < s.size(); i++) {
- columns[i][s[i]]++;
- if (!cflags[s[i] - 'A']) {
- cflags[s[i] - 'A'] = true;
- acids.push_back(s[i]);
- }
- }
- }
- int main() {
- //ios::sync_with_stdio(0);
- //cin.tie(NULL);
- ifstream in("input.txt");
- freopen("output.txt", "w", stdout);
- string s;
- in >> s;
- columns.resize(s.size());
- inc_columns(s);
- int k = 1;
- while (in >> s) {
- strip(s);
- if (s.size() > 0) {
- k++;
- inc_columns(s);
- }
- }
- if (k == 1) {
- return 0;
- }
- long double t = s.size() * k * (k - 1) / 2.0;
- sort(acids.begin(), acids.end());
- matrix.resize(acids.size(), vector<long double>(acids.size(), 0));
- for (int i = 0; i < acids.size(); i++) {
- for (int j = 0; j < acids.size(); j++) {
- long double pairs = 0;
- for (auto& c: columns) {
- if (i == j) {
- pairs += (int)(c[acids[i]] * (c[acids[i]] - 1)) / (int)2;
- } else {
- pairs += (int)(c[acids[i]] * c[acids[j]]);
- }
- }
- matrix[i][j] = pairs / t;
- }
- }
- vector<long double> P(acids.size(), 0);
- for (int i = 0; i < acids.size(); i++) {
- for (int j = 0; j < acids.size(); j++) {
- if (i != j) {
- P[i] += matrix[j][i];
- }
- }
- P[i] = P[i] / 2.0 + matrix[i][i];
- }
- S.resize(acids.size(), vector<long double>(acids.size(), 0));
- for (int i = 0; i < acids.size(); i++) {
- for (int j = 0; j < acids.size(); j++) {
- long double e = P[i] * P[j];
- if (i != j) {
- e *= 2.0;
- }
- if (matrix[i][j] != 0) {
- S[i][j] = round(2.0 * log2(matrix[i][j] / e));
- }
- }
- }
- for (int i = 0; i < S.size(); i++) {
- for (int j = 0; j < S[i].size(); j++) {
- if (j <= i) {
- if (S[i][j] == 0) {
- S[i][j] = abs(S[i][j]);
- }
- cout << S[i][j] << " ";
- }
- }
- cout << endl;
- }
- return 0;
- }
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement