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

自己测试对了但是提交是WA( `д′),求助

Posted by zqu971223 at 2016-07-01 21:56:24 on Problem 1007
#include <iostream>
#include <fstream>
#include <map>
#include <algorithm>
#include <string>

using namespace std;

int find_inver(string str)
{
    int length=str.length();
    int i,j,inversion=0;
    for(i=0;i<length;++i)
    {
        for(j=i+1;j<length;++j)
        {
            if(str[i]>str[j]) inversion++;
        }
    }
    return inversion;
}

int main()
{
    /*fstream infile("test.txt");
    if(!infile) {cerr<<"open file error!\n";return 1;}*/
    int n,m;
    //infile>>n>>m;
    cin>>n>>m;

    int i,inversion;
    string str;
    map<int,string> Map;

    for(i=0;i<m;++i)
    {
        //infile>>str;
        cin>>str;
        inversion=find_inver(str);
        Map[inversion]=str;
    }

    map<int,string>::iterator itr;
    for(itr=Map.begin();itr!=Map.end();itr++)
        cout<<itr->second<<endl;
    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