估计还是用C++比较好写些
[ 本帖最后由 fanpengpeng 于 2013-4-11 21:23 编辑 ]
[ 本帖最后由 fanpengpeng 于 2013-4-11 21:23 编辑 ]
人生是一场错过 愿你别蹉跎
#include <iostream> #include <fstream> #include <string> #include <vector> #include <map> using namespace std; const char FILE1[] = "index.txt"; const char FILE2[] = "KEGG_p-value.txt"; const char FILE3[] = "OUT.txt"; int main() { ifstream in1(FILE1), in2(FILE2); ofstream out(FILE3); map<string, string> datmap; vector<string> index; string s, value; while (in1 >> s) { if (s[0] != '0' && s[1] == '.') s = "0" + s; //Start with 0 index.push_back(s); datmap.insert(pair<string, string>(s, string())); } while (in2 >> s) { if (s > "9") value = s; else datmap[s] += "\t" + value; } vector<string>::iterator beg = index.begin(); vector<string>::iterator end = index.end(); for (; beg != end; beg++) { *beg += datmap[*beg]; out << *beg << "\n"; } return 0; }