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

感谢楼主啊~

Posted by justshine at 2009-05-23 21:44:03 on Problem 1007
In Reply To:搞不懂为什么要改成51 Posted by:springtty at 2008-10-18 20:23:07
我也是类似的方法实现,一样出错,改成51就过了,多谢楼主提醒啊
同时鄙视自己没学好C语言哈
这是我最后通过的方法:
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
struct myStruct{
	char c[51];
	int flag;
};
bool lower(myStruct elem1,myStruct elem2)
{
	return elem1.flag < elem2.flag;
}
int main(){
	vector <myStruct> v1;
	myStruct m1;
	char temp[51];
	int n,m;
	cin>>n>>m;
	for(int k=0;k<m;k++){
		int count=0;
		cin>>temp;
		strcpy_s(m1.c ,temp);
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				if(temp[i]>temp[j]){
					count++;
				}
			}
		}
		m1.flag=count;
		v1.push_back(m1);
	}
	sort( v1.begin(),v1.end(),lower);
	for(int i=0;i<v1.size();i++)
	{
		cout<<v1[i].c<<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