题解

136 条题解

  • 0
    @ 2006-10-11 14:01:20

    ..第一次用C++的运算符重载....

    很不习惯....调试了几十分钟= =

    发现错误很难改..= =..导致代码非常长(基本是重复的)....

    郁闷中..

    注:本题数据好象不大..我开到2000位就过了..

  • 0
    @ 2006-10-10 23:24:40

    rogerduck

    字符数组才是王道

    楼下的可以去参加IOCCC比赛了

    ( 2006-10-10 20:26:21 )

    IOCCC是C语言的

  • 0
    @ 2006-10-10 20:26:21

    字符数组才是王道

    楼下的可以去参加IOCCC比赛了

  • 0
    @ 2006-10-10 19:44:18

    啊,貌似用冒泡的就可以了

  • 0
    @ 2006-10-10 14:19:23

    用ANSISTING就OK了,没有必要什么高精度来处理那么麻烦!注意的是:字符串的比较,用字符串来储存数字,比较的时候要注意,先比较字符串长度,长度相等的再比较字符串大小,还有,之前应该先让NAME排序先,这样可以避免出现相同帖子数时候的情况,

  • 0
    @ 2006-10-10 22:09:09

    应该是l2:=length(b[j])?

  • 0
    @ 2006-10-11 20:03:45

    出自OIBH Online Judge..

    顺手练了基数排序..

  • 0
    @ 2006-10-09 17:10:16

    数据十分十分小,用int64或qword就行拉

    我100哦~!!!

  • -1
    @ 2017-07-21 15:25:31
    #include <iostream>
    #include <iterator>
    #include <set>
    
    struct king{
      std::string sorce;
      std::string name;
    };
    bool operator<(king lhs, king rhs)
    {
      if(lhs.sorce.size() < rhs.sorce.size()) return true;
      if(lhs.sorce.size() > rhs.sorce.size()) return false;
      if(lhs.sorce == rhs.sorce) return lhs.name > rhs.name;
      return lhs.sorce < rhs.sorce;
    }
    std::ostream& operator<<(std::ostream& out, king k)
    {
      out << k.name << std::endl;
      return out;
    }
    
    int main([[maybe_unused]] int argc, [[maybe_unused]] const char *argv[])
    {
      int n;
      std::cin >> n;
      std::set<king> v;
      for (int i = 0; i < n; ++i) {
        std::string s, n;
        std::cin >> n >> s;
        v.insert({s, n});
      }
      std::copy(v.crbegin(), v.crend(),
          std::ostream_iterator<king>(std::cout));
    }
    
  • -1
    @ 2016-11-30 11:55:00
    评测结果
    编译成功
    
    测试数据 #0: Accepted, time = 0 ms, mem = 588 KiB, score = 5
    测试数据 #1: Accepted, time = 0 ms, mem = 596 KiB, score = 15
    测试数据 #2: Accepted, time = 0 ms, mem = 592 KiB, score = 20
    测试数据 #3: Accepted, time = 0 ms, mem = 592 KiB, score = 25
    测试数据 #4: Accepted, time = 0 ms, mem = 592 KiB, score = 35
    Accepted, time = 0 ms, mem = 596 KiB, score = 100
    代码
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    struct water {
        string name,num;
    }v[1001];
    int n;
    int cmp(water x,water y) {
        if(x.num.length() != y.num.length()) return x.num.length() > y.num.length();
        if (x.num != y.num) return x.num>y.num;
        return x.name<y.name;
        return 0;
    }
    void solve() {
        scanf("%d",&n);
        for (int i = 1;i <= n;i++) cin >> v[i].name >> v[i].num;
        sort(v+1,v+n+1,cmp);
        for (int i = 1;i <= n;i++) cout << v[i].name << endl;
    }
    int main() {
        solve();
        return 0;
    }
    
  • -1
    @ 2016-11-13 16:43:31

    看那么多神犇都写那么一大串……作为蒟蒻我好慌。
    不再多说,思路如下
    读入数据
    把位数小的高精度高位补零
    直接用string的compare。
    c++
    #include <iostream>
    #include <string>
    #include <algorithm>
    using namespace std;
    struct info{
    string name, num;
    friend bool operator <(info a,info b){
    if(a.num!=b.num) return a.num>b.num;
    return a.name<b.name;
    }
    };
    int main(){
    info s[1000];/*
    ,,
    .。
    ::
    ;;
    -—
    ?? */
    int n;
    cin>>n;
    unsigned int length=0;
    for(int i=0;i<n;i++){
    cin>>s[i].name>>s[i].num;
    if(s[i].num.size()>length) length=s[i].num.size();
    }
    for(int i=0;i<n;i++){
    if(s[i].num.size()<length){
    for(int j=s[i].num.size();j<=length;j++){
    s[i].num='0'+s[i].num;
    }
    }
    }
    sort(s,s+n);
    for(int i=0;i<n;i++){
    cout<<s[i].name<<endl;
    }
    return 0;
    }

  • -1
    @ 2016-11-11 22:44:43

    var s1,s2:array[1..1000]of ansistring;
    n,x,y,i,j:longint;

    procedure change( var x,y:ansistring);
    var t:ansistring;
    begin
    t:=x;x:=y;y:=t;
    end;

    begin
    readln(n);
    for i:=1 to n do
    begin
    readln(s1[i]);
    readln(s2[i]);
    end;
    for i:=1 to n-1 do
    for j:=1 to n-i do
    begin
    x:=length(s2[j]);y:=length(s2[j+1]);
    if (x<y)or((x=y)and(s2[j]<s2[j+1]))or((x=y)and(s2[j]=s2[j+1])and(s1[j]>s1[j+1]))then
    begin
    change(s1[j],s1[j+1]);change(s2[j],s2[j+1]);
    end;
    end;
    for i:=1 to n do writeln(s1[i]);
    end.

  • -1
    @ 2016-09-17 11:40:26

    因为该题的数的长度很大,所以可以用基数排序(也叫“桶排序”)。
    另外,要注意**“若几个ID的发贴数相同,则按照ID的字典顺序先后排列。”**
    以下为代码
    ···
    c++
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<iostream>
    using namespace std;
    const int maxn=1000,maxlen=10000;
    struct preson
    {
    char num[maxlen],name[maxlen];
    int len;
    }p[maxn],a[10][maxn];
    int c[10];
    void qsort(int l,int r)
    {
    int i,j;
    struct preson n;
    i=l;
    j=r;
    n=p[(l+r)/2];
    while (i<j)
    {
    while (strcmp(n.name,p[i].name)==1&&i<r) i++;
    while (strcmp(n.name,p[j].name)==-1&&j>l) j--;
    if (i<=j)
    {
    swap(p[i],p[j]);
    i++;
    j--;
    }
    }
    if (i<r) qsort(i,r);
    if (j>l) qsort(l,j);
    }
    int main()
    {
    int i,j,k,l=0,n;
    bool check;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
    scanf("%s",&p[i].name);
    scanf("%s",&p[i].num);
    p[i].len=strlen(p[i].num);
    for(j=0,k=p[i].len-1;j<k;j++,k--) swap(p[i].num[j],p[i].num[k]);
    }
    do
    {
    check=false;
    memset(c,0,40);
    for(i=0;i<n;i++)
    if (p[i].len>l)
    {
    check=true;
    a[p[i].num[l]-48][c[p[i].num[l]-48]++]=p[i];
    }else a[0][c[0]++]=p[i];
    k=0;
    for(i=9;i>=0;i--)
    for(j=0;j<c[i];j++)
    p[k++]=a[i][j];
    l++;
    }while(check);
    for(i=0;i<n;i=j)
    {
    for(j=i+1;strcmp(p[i].num,p[j].num)==0&&j<n;j++);
    if (strcmp(p[i].num,p[j-1].num)==0&&i<j-1) qsort(i,j-1);
    }
    for(i=0;i<n;i++) printf("%s\n",p[i].name);
    return 0;
    }
    ```

  • -1
    @ 2016-09-09 01:07:02

    若几个ID的发贴数相同,则按照ID的字典顺序先后排列。
    简单高精度,不用计算,只是比大小。所以用c++的string。(注意string比较大小是按字母表比大小形式比的,所以string表示数时,不能直接用“>”,“<”,比较,但是可以用“==”;)
    例如 "abc">"aaa" "abc">"aaaa" (按照字母表"aaaa"在"abc"前)
    所以 "123">"1111" 在string中是正确的,所以用函数,当且仅当字符串长度相等时可以用">","<"。
    因为字符串相等时,长度一定相等,所以可以用“==”
    ***下面pd()的原理!!! ***

    #include <iostream>
    #include <string>

    using namespace std;

    string num[1000];//贴数
    string name[1000];//名字

    inline bool pd(string a,string b)//num[a]<num[b]```return true;//“数字的string比大小仍然是按字母表形式,所以用函数来比较大小 ”
    {
    if(a.size()<b.size())return true;
    else if(a.size()>b.size())return false;
    else if(a<b)return true;
    else return false;
    }

    inline void ksort(int l,int r,bool xiao)//xiao true排贴数,false排字母表
    {
    if(l==r)return;
    string mid;

    if(xiao)
    mid=num[(l+r)/2];//贴数
    else mid=name[(l+r)/2];//字母表

    int i=l,j=r;
    string temp;
    do
    {
    if(xiao)//贴数
    {
    while( pd(mid,num[i]) )++i;
    while( pd(num[j],mid) )--j;
    }else//字母表
    {
    while( name[i]<mid )++i;
    while( name[j]>mid )--j;
    }
    if(i<=j)
    {
    temp=num[i];
    num[i]=num[j];
    num[j]=temp;
    temp=name[i];
    name[i]=name[j];
    name[j]=temp;
    ++i;
    --j;
    }
    }while(i<=j);
    if(xiao)//贴数
    {
    if(l<j)ksort(l,j,true);
    if(i<r)ksort(i,r,true);
    }else//字母表
    {
    if(l<j)ksort(l,j,false);
    if(i<r)ksort(i,r,false);
    }
    return;
    }

    int main()
    {
    int n;
    int i;
    cin>>n;
    for(i=0;i<n;++i)
    cin>>name[i]>>num[i];//输入
    ksort(0,n-1,true);//排序
    int len;//挑选贴数相同的拍字母表
    for(i=0;i<n;++i)
    {
    len=0;
    for(len=0;len+i+1<n;++len)
    {
    if( num[len+i+1]!=num[len+i] )break;
    }
    if(len!=0)ksort(i,i+len,false);//i是起点,len是长度
    }
    for(i=0;i<n;++i)
    cout<<name[i]<<endl;
    return 0;
    }

  • -1
    @ 2016-07-13 12:19:49

    只过了第一个点的一般是没看到“若几个ID的发贴数相同,则按照ID的字典顺序先后排列。”这句话。。
    ~~~
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    using namespace std;
    struct king{
    char name[35];
    char num[205];
    }w[1005];
    int cmp(const void *x,const void *y){
    king a=(king)x;
    king b=(king)y;
    int len1=strlen(a->num),len2=strlen(b->num);
    if(len1==len2) {
    int x=-strcmp(a->num,b->num);
    if(x==0) return strcmp(a->name,b->name);
    else return x;
    }
    else return len2 - len1;
    }
    int n;
    int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
    scanf(" %s",w[i].name);
    scanf(" %s",w[i].num);
    }
    qsort(w,n,sizeof(w[0]),cmp);
    for(int i=0;i<n;i++){
    printf("%s\n",w[i].name);
    }
    return 0;
    }

  • -1
    @ 2016-03-13 15:06:37

    评测结果
    编译成功

    foo.cpp: In function 'bool compare(const char*, const char*)':
    foo.cpp:54:1: warning: control reaches end of non-void function [-Wreturn-type]
    }
    ^
    测试数据 #0: Accepted, time = 0 ms, mem = 556 KiB, score = 5
    测试数据 #1: Accepted, time = 0 ms, mem = 556 KiB, score = 15
    测试数据 #2: Accepted, time = 0 ms, mem = 552 KiB, score = 20
    测试数据 #3: Accepted, time = 0 ms, mem = 552 KiB, score = 25
    测试数据 #4: Accepted, time = 0 ms, mem = 552 KiB, score = 35
    Accepted, time = 0 ms, mem = 556 KiB, score = 100

    重载运算符
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;

    const int maxM = 10000 + 10;

    int N;

    class BIGNUMBER {
    public:
    friend istream& operator >> (istream &, BIGNUMBER &);

    BIGNUMBER operator = (const char *num)
    {
    length = strlen(num);
    number = new int [length];
    for(int i = 0;i < length; ++i)
    number[i] = num[length - i - 1] - '0';
    return *this;
    }
    bool operator < (const BIGNUMBER &X) const {
    if(X.length != length) return X.length < length;
    for(int i = length - 1; i >= 0; --i)
    if(X.number[i] != number[i]) return X.number[i] < number[i];
    return 0;
    }
    bool operator != (const BIGNUMBER &X) const {
    if(X.length != length) return 1;
    for(int i = length - 1; i >= 0; --i)
    if(X.number[i] != number[i]) return 1;
    return 0;
    }
    private:
    int *number;
    int length;
    };

    istream& operator >> (istream &is, BIGNUMBER &element) {
    char NUMBER[maxM];
    is >> NUMBER;
    element = NUMBER;
    return is;
    }

    inline bool compare(const char *X, const char *Y) {
    int lengthX = strlen(X);
    int lengthY = strlen(Y);
    int length = min(lengthX, lengthY);
    for(int i = 0; i != length; ++i)
    if(X[i] != Y[i]) return X[i] < Y[i];
    if(lengthX != lengthY) return lengthX < lengthY;
    }

    struct Data {
    char name[25];
    BIGNUMBER number;

    bool operator < (const Data &X) const {
    if(X.number != number) return X.number < number;
    return compare(X.name, name);
    }
    };//people[maxN];

    int main() {
    scanf("%d", &N);
    Data *people = new Data [N + 1];
    for(int i = 1; i <= N; ++i) {
    scanf("%s", people[i].name);
    cin >> people[i].number;
    }
    sort(people + 1, people + N + 1);
    for(int i = N; i != 0; --i) {
    cout << people[i].name;
    printf("\n");
    }
    delete [] people;
    people = NULL;
    return 0;
    }

  • -1
    @ 2015-10-24 07:56:06

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    struct water{
    string name;
    string num;
    }f[1001];
    int n;
    int comp(const water&x,const water&y)
    {
    if(x.num.length()>y.num.length()){
    return 1;
    }
    if(x.num.length()<y.num.length()){
    return 0;
    }
    if(x.num>y.num){
    return 1;
    }
    if(x.num<y.num){
    return 0;
    }
    if(x.name<y.name){
    return 1;
    }
    return 0;
    }
    void init()
    {
    int i,j;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
    cin>>f[i].name>>f[i].num;
    }
    sort(f+1,f+n+1,comp);
    }
    void print()
    {
    int i;
    for(i=1;i<n;i++){
    cout<<f[i].name<<endl;
    }
    cout<<f[n].name;
    }
    int main()
    {
    init();
    print();
    return 0;
    }

  • -1
    @ 2015-08-04 15:53:05

    双关键字排序

  • -1
    @ 2015-03-01 08:34:56

    program cc;
    var n,i,j:longint;
    b,p:ansistring;
    s:array[1..10000]of ansistring;
    name:array[1..1000]of ansistring;
    begin
    readln(n);
    for i:=1 to n do
    begin
    readln(name[i]);
    readln(s[i]);
    end;
    begin
    for i:=1 to n-1 do
    for j:=i+1 to n do
    if (length(s[i])<length(s[j]))or((s[i]=s[j])
    and (name[i]>name[j]))or ((length(s[i])=length(s[j]))and (s[i]<s[j]))then
    begin
    p:=s[i];s[i]:=s[j];s[j]:=p;
    b:=name[i];name[i]:=name[j];name[j]:=b;
    end;
    end;
    for i:=1 to n do
    writeln(name[i]);
    end.

  • -1
    @ 2015-02-15 11:13:22

    AC50纪念
    ACACACAC ACACACACACACA
    AC AC AC AC
    AC AC AC ACACAC
    AC AC AC AC
    AC AC AC AC

    AC ACACACAC
    AC AC
    ACACAC AC
    AC

信息

ID
1257
难度
6
分类
其他 | 排序 点击显示
标签
(无)
递交数
4108
已通过
1158
通过率
28%
被复制
3
上传者