• hdu 1263 水题一道


    水题,不过还是挺考查对STL的熟悉程度的,我用的set做,居然也用了好长时间。

    /*
    * hdu1263/win.cpp
    * Created on: 2011-10-13
    * Author : ben
    */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <map>
    #include <stack>
    #include <string>
    #include <vector>
    #include <deque>
    #include <list>
    #include <functional>
    #include <numeric>
    #include <cctype>
    using namespace std;
    typedef struct {
    char name[90];
    char addr[90];
    int num;
    } Fruit;

    bool inline operator<(const Fruit &f1, const Fruit &f2) {
    int r1 = strcmp(f1.addr, f2.addr);
    if (r1 != 0) {
    return r1 < 0;
    } else {
    return strcmp(f1.name, f2.name) < 0;
    }
    }

    bool inline operator==(const Fruit &f1, const Fruit &f2) {
    return (!strcmp(f1.name, f2.name)) && (!strcmp(f1.addr, f2.addr));
    }

    int main() {
    #ifndef ONLINE_JUDGE
    freopen("data.in", "r", stdin);
    #endif
    int T, M;
    char lastaddr[100];
    scanf("%d", &T);
    while (T--) {
    set<Fruit> myset;
    scanf("%d", &M);
    Fruit temp;
    for (int i = 0; i < M; i++) {
    scanf("%s %s %d", temp.name, temp.addr, &temp.num);
    if (myset.count(temp) != 0) {
    temp.num += (*(myset.find(temp))).num;
    myset.erase(temp);
    }
    myset.insert(temp);
    }
    set<Fruit>::iterator it;
    it = myset.begin();
    memset(lastaddr, 0, sizeof(lastaddr));
    while (it != myset.end()) {
    if (strcmp((*it).addr, lastaddr) != 0) {
    strcpy(lastaddr, (*it).addr);
    puts((*it).addr);
    }
    printf(" |----%s(%d)\n", (*it).name, (*it).num);
    it++;
    }
    if (T > 0) {
    putchar('\n');
    }
    }
    return 0;
    }



  • 相关阅读:
    Typora Writings
    Xcode7.3 beta 新功能
    最美应用API接口分析
    'Project Name' was compiled with optimization
    web前端开发与iOS终端开发的异同[转]
    2015-12-19_16_30_15
    Xcode搭建Python编译环境
    jsPach.qq.com
    Q&AApple’s Craig Federighi talks open source Swift, Objective-C and the next 20 years of development
    .NET Core项目与传统vs项目的细微不同
  • 原文地址:https://www.cnblogs.com/moonbay/p/2210171.html
Copyright © 2020-2023  润新知