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

Re:实在找不到错误的原因,不可救药吗? 代码……

Posted by C061200548322 at 2006-05-21 20:27:14 on Problem 2159
In Reply To:实在找不到错误的原因,不可救药吗? 代码…… Posted by:C061200548322 at 2006-05-21 20:26:55
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;

int cmp(const void * a,const void * b)
{
	return ( * (char * )a - * (char * ) b);
}

int  main()
{
	int i,len1;
	string s1,fromS1,code="BCDEFGHIJKLMNOPQRSTUVWXYZA";

	bool stop = false;
	cin>>fromS1>>s1;
	
	len1 = s1.length();
	string mid(len1, ' '); //必须声明并定义时才可以用(len1, ' ')
	
	for( i=0; i<len1; i++ )		
		mid.at(i) = code.at( s1.at(i) - 'A' );

	char * pmid = new char[len1 +1];
	strcpy(pmid,mid.c_str());
	//mid.copy (pmid,len1,0);
	char * pfrom = new char[len1 +1];
	//fromS1.copy(pfrom,len1,0);
	strcpy(pfrom,fromS1.c_str());
	qsort(pmid, len1, sizeof(pmid[0]),cmp);
	qsort(pfrom,len1,sizeof(pfrom[0]),cmp);
	//cout<<pfrom<<"  "<<pmid<<endl;
	
	int right=strcmp(pmid, pfrom );		
    
	if (right==0 ) cout<<"YES\n";
	else cout<<"NO\n";
	
	return 1;
}

	

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