写的丑死
未AC
搞不懂
//#include "stdafx.h"
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
class LINT
{
friend ostream& operator<<(ostream& out, LINT& e);
private :
char num[100];
public :
LINT(){num[0]='\0';}
LINT(char *m){strcpy(num,m);}
LINT(int a);
bool operator>(const LINT& m);
};
/*
功能:初始化
输入:int a
输出:
日期:
*/
LINT::LINT(int a)
{
if (a==0) { num[0]='0';num[1]='\0';return;}
int i=0;
while (a)
{
num[i++] = a % 10;
a /= 10;
}
num[i]='\0';
int len = strlen(num);
for (i=0; i<strlen(num); i++)
{
char tmp = num[len-i-1];
num[len-i-1] = num[i];
num[i] = tmp;
}
return;
}
/*
功能:重载运算符
输入:LINT a,b
输出:a>b 成立 1 否则 0
日期
*/
bool LINT::operator>(const LINT &m)
{
return strcmp(num, m.num)>0;
}
/*
功能:重载输出运算符
输入:LINT e
输出:
日期:
*/
ostream& operator<<(ostream &out, LINT& e)
{
out<<e.num;
return out;
}
class LIST
{
private :
LINT n[100];
int len;
public:
LIST(int n=0){len=n;}
void Add(LINT e);
void Sort();
void Print();
LINT GetAt(int i){return n[i];}
int GetLen(){return len;}
};
/*
功能:Add
输入:LINT e
输入:无
日期:
*/
void LIST::Add(LINT e)
{
n[len++]=e;
}
/*
功能:Sort 从大到小
输入:无
输入:无
日期:
*/
void LIST::Sort()
{
int i,j;
for (i=0; i<len; i++)
{
for (j=0; j<len-1-i; j++)
{
if (n[j+1]>n[j])
{
LINT tmp = n[j+1];
n[j+1] = n[j];
n[j]=tmp;
}
}
}
}
/*
功能:输出显示
输入:无
输出:无
日期:
*/
void LIST::Print()
{
for (int i=0; i<len; i++) cout<<"第 "<<i<<" :值:"<<n[i]<<endl;
}
class STRING
{
friend istream& operator>>(istream &in,STRING& str);
friend ostream& operator<<(ostream &out,STRING& str);
private :
char n[1000];
public :
STRING(){n[0]='\0';}
STRING* Split(char a);
int GetLen();
char * ConvertToCharArray();
};
int STRING::GetLen(){return strlen(n); }
STRING* STRING::Split(char a)
{
STRING* pStr = new STRING[100];
int k=0,kp=0;
int len = strlen(n);
for (int i=0; i<len; )
{
while(n[i]==a && i<len) i++;//找到第一个非空格
kp=0;
while (n[i]!=a&&i<len)
{
pStr[k].n[kp++]=n[i++];
}
pStr[k++].n[kp]='\0';
}
return pStr;
}
istream& operator>>(istream&in ,STRING&str)
{
gets(str.n);
return in;
}
ostream& operator<<(ostream&out, STRING&str)
{
out<<str.n;
return out;
}
char * STRING::ConvertToCharArray()
{
char * p = new char [1000];
strcpy(p,n);
return p;
}
int main()
{
LINT a("123") ;
LINT b("45");
LINT c("132");
LIST lst;
int k;
cin>>k;
getchar();
STRING str;
cin>>str;
STRING * pStr = str.Split(' ');
int i=0;
while ( pStr[i].GetLen() >0)
{
char *p = pStr[i].ConvertToCharArray();
lst.Add(p);
delete p;
i++;
}
lst.Sort();
for (int i=0; i<lst.GetLen(); i++)
{
LINT p = lst.GetAt(i);
cout<<p;
}
cout<<endl;
delete pStr;
//system("pause");
return 0;
}