hdu 1263 水果
来源:互联网 发布:大头贴软件 编辑:程序博客网 时间:2024/05/01 11:02
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1263
简单题,练习一下vector,具体如下:
#include<iostream>#include<vector>#include <cstring>#include<algorithm>#define rt place[i].valconst int Max_N = 110;typedef char State[82];struct node{ State list; int val; }x1, x2;std::vector<node> rec[Max_N], place;int cmp(const node & a, const node & b){return strcmp(a.list, b.list) == -1 ? 1 : 0;}bool is_exist(std::vector<node> ve, char *pls){for (int i = 0; i < ve.size(); i++){if (0 == strcmp(pls, ve[i].list)) return true;}return false;}int main(){#ifdef LOCALfreopen("in.txt", "r", stdin);freopen("out.txt", "w+", stdout);#endifint t, n, i, k;scanf("%d", &t);while (t--){k = 0;scanf("%d", &n);for (i = 0; i < n; i++){scanf("%s %s %d", x2.list, x1.list, &x2.val);if (0 == place.size() || !is_exist(place, x1.list)){x1.val = k;place.push_back(x1), rec[k++].push_back(x2);} else {int flag = 0, d = 0;for (int j = 0; j < place.size(); j++){if (0 == strcmp(x1.list, place[j].list)){d = j;break;}}for (int j = 0; j < rec[d].size(); j++){if (0 == strcmp(x2.list, rec[d][j].list)){rec[d][j].val += x2.val;flag = 1;break;}}if (!flag) rec[d].push_back(x2);}}std::sort(place.begin(), place.end(), cmp);for (i = 0; i < k; i++){std::sort(rec[rt].begin(), rec[rt].end(), cmp);printf("%s\n", place[i].list);for (int j = 0; j < rec[rt].size(); j++){printf(" |----%s(%d)\n", rec[rt][j].list, rec[rt][j].val);}rec[rt].clear();}place.clear();if (t > 0) printf("\n");}return 0;}
0 0
- hdu 1263 水果
- hdu - 1263 水果
- HDU 1263 水果
- hdu 1263 水果
- HDU 1263 水果
- 水果 hdu 1263 模拟
- HDU 1263 水果
- HDU 1263 水果
- hdu 1263 水果
- HDU 1263 水果
- hdu 1263 水果
- hdu 1263 水果
- hdu 1263 水果
- hdu 1263 水果
- hdu 1263 水果
- HDU 1263 水果
- HDU 1263 水果
- ACM HDU 1263水果
- neutron ml2
- 第六周项目二 深复制之我的数组类
- java io 缓冲流
- 2.6
- Java学习笔记—第四章
- hdu 1263 水果
- JSTL 核心标签库
- 队列
- 读取csv文件转换成你自己想要格式的数据
- 经典SQL语句大全
- 换位思考让烦恼少一点
- 【记乙未帝都魔友景山盛会】
- hdu 1021 Fibonacci Again(同余模定理+斐波那契数列)
- discuz! X3 更改域名全程记录 (修改域名的方法)