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

wrong answer

Posted by jyf at 2011-04-19 23:07:38 on Problem 1007
#include<iostream>
#include<stdio.h>
#include<set>
using namespace std;
int count(string str);
struct cmp
{
    bool operator() (string str1,string str2)
    {
        int count1=count(str1);
        int count2=count(str2);
        return count1<count2;
    }
};
int main(void)
{
    int n,m;
    scanf("%d %d",&n,&m);
    string str;
    set<string,cmp> s;
    for(int i=0;i<m;i++)
    {
        cin>>str;
        s.insert(str);
    }
    for(set<string>::iterator it=s.begin();it!=s.end();it++)
    {
        cout<<*it<<endl;
    }
    return 0;
}
int count(string str)
{
    int length=str.length();
    int count=0;
    for(int i=0;i<length;i++)
    {
        for(int j=i+1;j<length;j++)
        {
            if(str[i]>str[j])
            {
                count++;
            }
        }
    }
    return count;
}

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