~Cpp #include<iostream> #include<fstream> #include<math.h> #include<vector> #include<string> #include<map> using namespace std; typedef struct Data{ string s; int w; float frq; }Data; int main(){ ifstream f; ifstream f2; map<string,int> economy; map<string,int> politics; int eco = 1721761; int pol = 1760048; f.open("C:/package/train/economy/index.economy.db"); f2.open("C:/package/train/politics/index.politics.db"); while(1){ if(f.eof()) break; string s; f >> s; economy[s]++; } while(1){ if(f2.eof()) break; string s; f2 >> s; politics[s]++; } f.close(); f2.close(); ifstream f3; ifstream f4; f3.open("C:/package/test/economy/economy.txt"); f4.open("C:/package/test/politics/politics.txt"); double frq = 0; while(1){ if(f3.eof()) break; string s; f3 >> s; double e = 0; e = economy[s]; double p = 0; p= politics[s]; if(e == 0 || e == NULL){p++;e=1;} if(p == 0 || p == NULL){p=1;e++;} frq = frq + log((e/eco)/(p/pol)); } cout << "Economy가 가 경제일 확률 " << frq << endl; frq = 0; while(1){ if(f4.eof()) break; string s; f4 >> s; double e = 0; e = economy[s]; double p = 0; p= politics[s]; if(e == 0 || e == NULL){p++;e=1;} if(p == 0 || p == NULL){p=1;e++;} frq = frq + log((p/pol)/(e/eco)); } cout << "Politics 가 정치일 확률 : " << frq << endl; cout << endl; return 0; }