Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

晒一下c++味道比较足的代码

Posted by osfpu at 2012-03-03 12:32:48 on Problem 1007
一次AC,代码如下:
//////////////////////////////////
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
//#include<cstdlib>
using namespace std;
struct DNA
{
    string seq;        //dna sequence
    int inver;         //unsortedness
    int order;         //the order of input
    DNA()
    {
        inver = 0;
    }    
};
bool cmp(DNA a, DNA b)
{
    if(a.inver < b.inver)
    {
        return true;
    }
    else if((a.inver == b.inver) && (a.order < b.order))
    {
        return true;
    }
    else
    {
        return false;
    }
}
void print(DNA a)
{
    cout<<a.seq<<endl;
}
int main()
{
    int n,m,i = 0;
    vector<DNA> dvec;
    cin>>n>>m;
    while(i++ < m)
    {
        DNA dt;
        dt.order = i;
        cin>>dt.seq;
        dvec.push_back(dt);
    }
    for(vector<DNA>::iterator diter = dvec.begin()
                        ; diter != dvec.end(); diter++)
    {
        for(string::iterator si1 = diter->seq.begin()
                                ;si1 != diter->seq.end(); si1++)
        {
             for(string::iterator si2 = si1
                             ;si2 != diter->seq.end(); si2++)
             {
                    if(*si1 > *si2)
                    {
                        ++(diter->inver);
                    }
             }         
        }
    }
    sort(dvec.begin(),dvec.end(),cmp);
    for_each(dvec.begin(),dvec.end(),print);
 //   system("PAUSE");
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator