zoukankan      html  css  js  c++  java
  • ytu 1061: 从三个数中找出最大的数(水题,模板函数练习 + 宏定义练习)

    1061: 从三个数中找出最大的数

    Time Limit: 1 Sec  Memory Limit: 128 MB
    Submit: 154  Solved: 124
    [Submit][Status][Web Board]

    Description

    定义一个带参的宏(或者模板函数),从三个数中找出最大的数。

    Input

    3个短整型数,空格隔开

    3个实数,空格隔开

    3个长整数,空格隔开

    Output

    最大的数,对于实数保留2位小数。

    Sample Input

    1 2 3
    1.5 4.7 3.2
    1234567 12345 12345678

    Sample Output

    3
    4.70
    12345678

    HINT

     主函数已给定如下,提交时不需要包含,会自动添加到程序尾部


     

    /* C++代码 */

     

    int main()

    {

        short int i1,i2,i3,maxi;

        double d1,d2,d3,maxd;

        long l1,l2,l3,maxl;

        cout<<setiosflags(ios::fixed);

        cout<<setprecision(2);

        cin>>i1>>i2>>i3;

        maxi=MAX(i1,i2,i3);

        cout<<maxi<<endl;

        cin>>d1>>d2>>d3;

        maxd=MAX(d1,d2,d3);

        cout<<maxd<<endl;

        cin>>l1>>l2>>l3;

        maxl=MAX(l1,l2,l3);

        cout<<maxl<<endl;

        return 0;

    }

     

    Source

     
      水题,模板函数练习 + 宏定义练习
      长时间不用,模板函数和宏定义都生疏了,回头重新巩固下。
      代码:
     1 #include <iostream>
     2 #include <iomanip>
     3 using namespace std;
     4 
     5 //宏定义
     6 //#define MAX(a,b,c) a>b?a>c?a:c:b>c?b:c;
     7 
     8 //模板函数
     9 template <class T>
    10 T MAX(T a,T b,T c)
    11 {
    12     if(a>b && a>c)
    13         return a;
    14     else if(b>a && b>c)
    15         return b;
    16     else if(c>a && c>b)
    17         return c;
    18     else
    19         return 0;
    20 }
    21 
    22 int main()
    23 {
    24     short int i1,i2,i3,maxi;
    25     double d1,d2,d3,maxd;
    26     long l1,l2,l3,maxl;
    27     cout<<setiosflags(ios::fixed);
    28     cout<<setprecision(2);
    29     cin>>i1>>i2>>i3;
    30     maxi=MAX(i1,i2,i3);
    31     cout<<maxi<<endl;
    32     cin>>d1>>d2>>d3;
    33     maxd=MAX(d1,d2,d3);
    34     cout<<maxd<<endl;
    35     cin>>l1>>l2>>l3;
    36     maxl=MAX(l1,l2,l3);
    37     cout<<maxl<<endl;
    38     return 0;
    39 }

    Freecode : www.cnblogs.com/yym2013

  • 相关阅读:
    【转】C++11优化使用emplace,emplace_back
    面试经历总结
    Hive常用函数
    股票指标
    Visual Studio Code 可以翻盘成功主要是因为什么?
    openpyxl模块操作Excel
    JavaScript(二)
    前端之CSS
    ps导出ICO格式
    Qt 所有版本官方下载地址
  • 原文地址:https://www.cnblogs.com/yym2013/p/3779458.html
Copyright © 2011-2022 走看看