Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 75079 | Accepted: 30074 |
Description
Input
Output
Sample Input
10 6 AACATGAAGG TTTTGGCCAA TTTGGCCAAA GATCAGATTT CCCGGGGGGA ATCGATGCAT
Sample Output
CCCGGGGGGA AACATGAAGG GATCAGATTT ATCGATGCAT TTTTGGCCAA TTTGGCCAAA#include <iostream> #include <map> #include <string> #include <vector> #include <algorithm> //#define MAXFORVALUE 1000 // 所能容纳的最大权值 using namespace std; typedef pair<string, int> PAIR; string *str=NULL; map<string, int> result; int count_num=0; int size = 0; string *repeat = new string[50]; int repeat_num = 0; void InputMessage(); void SortForValue(); void OutputMessage(); int main() { InputMessage(); SortForValue(); OutputMessage(); //int f; //cin >> f; return 1; } int cmp(const PAIR& x, const PAIR& y) { return x.second < y.second; } void OutputMessage() { map<string, int>::const_iterator map_it = result.begin(); vector<PAIR> vecpair; for(map<string, int>::iterator curr = result.begin(); curr != result.end(); ++curr) { vecpair.push_back(make_pair(curr->first, curr->second)); } sort(vecpair.begin(), vecpair.end(), cmp); int count_repeat = 0; int j = 0; int flag = false; for(unsigned int i=0; i < vecpair.size(); i++) { for(int j = 0; j < repeat_num; j++) { if(vecpair[i].first == repeat[j]) { cout << repeat[j] << endl; } } cout << vecpair[i].first << endl; } } void SortForValue() { int value = 0; //得到字串的权值 for(int i=0; i<count_num; i++) { for(int j=0; j < size; j++) { for(int k=j+1; k <size; k++) { if(str[i][j] > str[i][k]) { value++; } } } pair<map<string, int>::iterator, bool> ret = result.insert(make_pair(str[i], value)); if(!ret.second) //如果出现重复的字串 { repeat[repeat_num] = str[i]; repeat_num++; } value = 0; } } void InputMessage() { cin >> size >> count_num; str = new string[count_num]; for(int i=0; i < count_num; i++) cin >> str[i]; }
其实说实话,这道题目挺简单的,我觉得关键在于细节的处理方面。可是我却调试了2天......经过这一件事情,我觉得不管是在编写代码还是调试代码时都要心静,要同盘考虑
很享受在通过ACM 时,出现的那个“Accepted”!