| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 8009 人关注过本帖
标题:十个职工的姓名,职工号
取消只看楼主 加入收藏
zhb151017212
Rank: 1
等 级:新手上路
帖 子:41
专家分:6
注 册:2012-10-15
结帖率:73.33%
收藏
已结贴  问题点数:10 回复次数:2 
十个职工的姓名,职工号
/*输入十个职工的姓名,职工号。
按职工号大小顺序输出,姓名也随着调整。
要求输入一职工号,折半查找,从主函
数输入要查找的职工号,输出该职工的姓名。*/

#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,temp;int key;
    int p=0; char staffList[10];
    //char string[]
     char staffList[10]={{"刘翔","201003020076"},
                        {"姚明","20100302001"},
                        {"宋健","201003020077"},
                        {"宋丹丹","201003020054"},
                        {"马大文","201003020090"},
                        {"孙二林","201003020017"},
                        {"王三","201003020012"},
                        {"段五","201003020040"},
                        {"小六","201003020080"},
                        {"李四",201003020069"}};
    for(i=0;i<10;i++)
        scanf("staff=%lf\n",staffList[i]);
        for(j=0;j<10;j++)
            for(i=j;i<9-j;i++)
                if(staffList[i]>staffList[i+1]){
                    temp=staffList[i];
                staffList[i]=staffList[i+1];
                staffList[i+1]=temp;
                }
                for(i=0;i<10;i++)
                    printf("从小到大输出%f\n",staffList[i]);

                while(p==0){
                    printf("input a staff's number:\n");//折半查找???
                    scanf("%lf",&key);
                    if(key==staffList[i])
                    {
                        printf("%f ",staffList[i]);
                        p=1;
                    }
                            else{
                        
                        }
                    if(p==0)
                        printf("输入有误,重新出入!\n");
                }
                        return 0;        
}
//数组有误总改不对!求大神。。。
搜索更多相关主题的帖子: include 姓名 
2012-11-03 18:50
zhb151017212
Rank: 1
等 级:新手上路
帖 子:41
专家分:6
注 册:2012-10-15
收藏
得分:0 
回复 5楼 admin_xyz
三维数组 我也搞不清楚。。。谢谢哦。。。
2012-11-03 20:54
zhb151017212
Rank: 1
等 级:新手上路
帖 子:41
专家分:6
注 册:2012-10-15
收藏
得分:0 
学了结构体用结构体能实现。
#include<stdio.h>   
struct Staff{
        char  name[20];
        double num;
    };
int main()
{
    int i,j, p=0;
    double key;
    struct Staff temp;
struct Staff staff[10]={{"郑海兵",201003020076},
                        {"宋天琪",20100302001},
                        {"宋 健",201003020077},
                        {"李丹丹",201003020054},
                        {"马 文",201003020090},
                        {"孙家林",201003020017},
                        {"王 昆",201003020012},
                        {"段华鹏",201003020040},
                        {"小 六",201003020080},
                        {"李 勇",201003020069}};     
    for(i=0;i<10;i++)
        printf("%s %.0lf\n",staff[i].name,staff[i].num);
        for(j=0;j<10;j++)
            for(i=0;i<9-j;i++)
                if(staff[i].num>staff[i+1].num){
                    temp=staff[i];
                staff[i]=staff[i+1];
                staff[i+1]=temp;
                }
                for(i=0;i<10;i++)
                    printf("从小到大输出:%s %.0lf\n",staff[i].name,staff[i].num);

                while(p==0){
                    printf("input a staff's number:\n");//折半查找???
                    scanf("%f",&key);
                    for(i=0;i<10;i++)
                    if(key==staff[i].num)
                    {
                        printf("%s %.0lf",staff[i].name,staff[i].num);
                        p=1;
                    }
                            else{
                        
                        }
                    if(p=0)
                        printf("输入有误,重新出入!\n");
                }
                        return 0;        
}
谢谢各位!
2012-11-04 16:38
快速回复:十个职工的姓名,职工号
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017459 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved