hdu 1234_sort的陷阱
2014-08-20 12:53
155 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1234
题目比较简单,用sort时遇到了点问题,这个函数要求对于调用的两个参数交换位置时不能得到相同的true的结果。
题目比较简单,用sort时遇到了点问题,这个函数要求对于调用的两个参数交换位置时不能得到相同的true的结果。
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int t,m,i; char fw[20],lg[20]; struct N{ char id[20],w[20],g[20]; }n[1000005]; bool cmp1(N a,N b) { return strcmp(a.w,b.w) < 0 ? true : false; /* 如果换成:return strcmp(b.w,a.w)则会出错,跟踪源代码得到: template inline bool __CLRCALL_OR_CDECL _Debug_lt_pred(_Pr _Pred, _Ty1& _Left, _Ty2& _Right, const wchar_t *_Where, unsigned int _Line) { // test if _Pred(_Left, _Right) and _Pred is strict weak ordering if (!_Pred (_Left, _Right)) return (false); else if (_Pred(_Right, _Left)) _DEBUG_ERROR2("invalid operator<", _Where, _Line); return (true); } 这个函数要求对于调用的两个参数交换位置时不能得到相同的true的结果。 */ } bool cmp2(N a,N b) { return strcmp(a.g,b.g) > 0 ? true : false; } int main() { scanf("%d",&t); while(t--) { scanf("%d",&m); for(i = 0; i < m; i++) { scanf("%s%s%s",&n[i].id,&n[i].w,&n[i].g); } sort(n, n + m,cmp1); strcpy(fw,n[0].id); sort(n, n + m,cmp2); strcpy(lg,n[0].id); printf("%s %s\n",fw,lg); } }
相关文章推荐
- hdu--1234 开门人和关门人(结构体+sort)
- 【hdu 1234】开门人和关门人 (sort &结构体)
- 开门人和关门人(sort)【HDU】-1234
- 【HDU1234】 开门人和关门人 (sort)
- hdu1234开门人和关门人用二维数组
- HDU 2689 sort it - from lanshui_Yang
- HDU 1425 sort(桶排序+哈希函数)
- hdu-Sort 二分
- HDU 2689 sort it - from lanshui_Yang
- 开门人和关门人 HDU - 1234
- HDU 2689 Sort it 求逆序数,树状数组实现
- HDU 1890:Robotic Sort Splay
- hdu sort again
- hdu 6034 Balala Power!(贪心)( 2017 Multi-University Training Contest - Team 1 )(无耻之sort)
- hdu 1234 开门人和关门人
- HDU-1280 前m大的数 【sort】
- 2016 ACM/ICPC Asia Regional Qingdao Online hdu 5884 Sort (智商+队列)★
- hdu_5884_Sort(二分+单调队列)
- HDU 5884 Sort(二分+单调队列)
- hdu 2689 sort it