zoukankan      html  css  js  c++  java
  • 习题9-4 查找书籍 (20 分)

    给定n本书的名称和定价,本题要求编写程序,查找并输出其中定价最高和最低的书的名称和定价。

    输入格式:

    输入第一行给出正整数n(<10),随后给出n本书的信息。每本书在一行中给出书名,即长度不超过30的字符串,随后一行中给出正实数价格。题目保证没有同样价格的书。

    输出格式:

    在一行中按照“价格, 书名”的格式先后输出价格最高和最低的书。价格保留2位小数。

    输入样例:

    3
    Programming in C
    21.5
    Programming in VB
    18.5
    Programming in Delphi
    25.0

    输出样例:

    25.00, Programming in Delphi
    18.50, Programming in VB

    提交:

    #include <stdio.h>
    #include <string.h>
    
    int main() {
        
        int n,i=0;
        double price=0,max=0,min=0;
        char * matr;//存储最大价格对应的书名
        char * mitr;//存储最小价格对应的书名
        scanf("%d
    ",&n);
        char a[n][31];
        for (i=0;i<n;i++) {
            gets(a[i]);
            scanf("%lf
    ",&price);
            if (max <= price) {//选出最大
                max = price;
                matr = a[i];
            }
            if (i==0) min = price; //最小值初始化
            if (min >= price) {//选出最小
                min = price;
                mitr = a[i];
            }
        }
        printf("%.2lf, %s
    ",max,matr);
        printf("%.2lf, %s",min,mitr);
        return 0;
    }
  • 相关阅读:
    转贴"三个月内通过Adsense赚一百万美金"
    今天申请了Google Adsense
    Asp.Net Core 多样性的配置来源
    Identity第二章
    Identity第一章
    Identity第三章 Authorize原理解析
    async和await
    ASP.Net Core简介
    【学习笔记】后缀数组 SA
    题解 [NOI2009] 植物大战僵尸
  • 原文地址:https://www.cnblogs.com/cgy-home/p/15095057.html
Copyright © 2011-2022 走看看