记录编号 97949 评测结果 AAAAAAAAAA
题目名称 注水猪肉 最终得分 100
用户昵称 Gravatar隨風巽 是否通过 通过
代码语言 C++ 运行时间 0.270 s
提交时间 2014-04-21 11:45:35 内存使用 8.07 MiB
显示代码纯文本
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
const int MAXN=2010,MAXP=1000+10;
struct bign
{
	int len,s[MAXN];
	string name;
	bign() 
    {
		memset(s,0,sizeof(s));
        len=1;
    }
	bign(int num){*this=num;}
    bign(const char* num){*this=num;}
    bign operator = (int num) 
    {
	 char s[MAXN];
        sprintf(s,"%d",num);//把num打印成字符串
        *this=s;
        return *this;
    }
    bign operator = (const char* num) 
    {
		len=strlen(num);
        for(int i=0;i<len;i++)
		s[i]=num[len-i-1]-'0';
        return *this;
    }
    string str() const 
    {
		string res="";
        for(int i=0;i<len;i++) 
		res=(char)(s[i]+'0')+res;
        if(res=="")res="0";
        return res;
    }
	bign operator + (const bign& b)const
    {
		bign c;c.len=0;
		int i,x,g;
        for(i=0,g=0;g||i<max(len,b.len);i++) 
	    {   //g表示上次进位的数
			x=g;
			if(i<len)x+=s[i];
            if(i<b.len)x+=b.s[i];
            c.s[c.len++]=x%10;
			if(c.len>500)break;
            g=x/10;
        }
		return c;
    }
    bool operator < (const bign& b)const
    {
		if(len!=b.len)return len<b.len;
		for(int i =len-1;i>=0;i--)
			if(s[i]!=b.s[i])return s[i]<b.s[i];
        return false;
    }
	bool operator == (const bign& b) 
	{
		return !(b<*this)&&!(*this<b);
    }
};
istream& operator >> (istream &in, bign& x) 
{
	string s;
	in>>s;
    x=s.c_str();                 
	return in;
}
ostream& operator << (ostream &out, const bign& x)
{
	out<<x.str();
	return out;
}
bool cmp(bign a,bign b){return (b<a)||(a==b&&a.name<b.name);}
int N,i;
bign pig[MAXP],ans; //////
int main()
{

	freopen("boss.in","r",stdin);
	freopen("boss.out","w",stdout);
	cin>>N;
	for(i=1;i<=N;i++)
	{	
		cin>>pig[i].name;
	    cin>>pig[i];
		ans=ans+pig[i];
	}
	sort(pig+1,pig+1+N,cmp);
	for(i=1;i<=N;i++)
		cout<<pig[i].name<<endl;
	ans.len=490;
	cout<<ans<<endl;
	return 0;
}