zoukankan      html  css  js  c++  java
  • 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;
    }



  • 相关阅读:
    Javascript小技巧
    VIM
    interview experience
    HTML5
    代码实践
    git clone 速度慢的解决办法
    vscode 找不到相对目录文件的解决办法
    python基础 13 类命名空间于对象、实例的命名空间,组合方法
    python 基础 12 初识类,类方法,类属性
    python 基础 11 带参数装饰器与递归函数
  • 原文地址:https://www.cnblogs.com/moonbay/p/2210171.html
Copyright © 2011-2022 走看看