付翔的专栏
在鄙视中成长 记录成长的点滴
posts - 106,  comments - 32,  trackbacks - 0

呵呵 直接看代码 就可以知道 C++ 很好很强大 自己受C 的影响太大额


#include
<iostream>
#include
<algorithm>
#include 
<vector>
#include 
<functional>

using namespace std;

const int maxn = 3000+10;
int data[maxn];
struct node
{
    
int x,y;
    
char name[20];
} re[maxn];
// bool cmp(const struct node a,const struct node b)
// {
//     return (a).x - (b).x;
// }
class cmp{
public:
    
bool operator()(const node &a,const node &b)
    {
        
//return a.x > b.x;
        if(strcmp(a.name,b.name) > 0)
            
return true;
        
return false;
    }
};

int main()
{
    
int N,M,i;
//    vector<int > re(maxn*maxn/2);
    
    
while(scanf("%d%d",&N,&M)!=EOF)
    {
        
for(i = 0; i < N; i ++)// 输入n个数字
            scanf("%s",&re[i].name);
        partial_sort(re,re
+M,re+M,cmp());//排出前M大个数字
        for( i = 0; i < M; i ++)
            
if(i ==0) cout<<re[i].name;
             
else cout<<" "<<re[i].name;
//         for( i = 0; i < M; i ++)
//             if(i ==0) cout<<re[i].x;
//             else cout<<" "<<re[i].x;
        printf("\n");
    }
    
return 0;


posted on 2010-05-26 09:14 付翔 阅读(489) 评论(0)  编辑 收藏 引用 所属分类: c++

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2010年5月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

常用链接

留言簿(2)

随笔分类

随笔档案

文章分类

文章档案

CSDN - 我的blog地址

博客

搜索

  •  

最新评论

阅读排行榜

评论排行榜