YTU 2642: 填空题:类模板---求数组的最大值
2642: 填空题:类模板---求数组的最大值
时间限制: 1 Sec 内存限制: 128 MB
提交: 646 解决: 446
题目描述
输入
10个int型数据
10个double型数据
10个char型数据
10gestring型数据
输出
10个int型数据的最大值
10个double型数据的最大值
10个char型数据的最大值
10个string型数据的最大值
样例输入
1 3 5 7 9 8 6 4 2 0
1.2 3.4 5.66 7.8 9.9 13.4 -2.5 6.7 0 -10
a b 1 2 + - A B p Z
guo li zhao sun zhou zhang yang lan zhai wang
样例输出
9
13.4
p
zhou
提示
只提交begin到end部分的代码
迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……
#include <iostream>
#include <string>
using namespace std;
template <class T>
class Array_max //声明类模板
{
public: //以下3行为成员函数原型声明
void set_value( ); //对数组元素设置值
T max_value( ); //找出数组中的最大元素
private:
T array[10]; //T类型数组
T max; //max用来存放数组中的最大值
};
template<class T>
void Array_max<T>::set_value( )
{
int i;
for (i=0; i<10; i++)
cin>>array[i];
}
template<class T>
T Array_max<T>::max_value( )
{
int i;
max=array[0];
for (i=1; i<10; i++)
max=max<array[i]?array[i]:max;
return max;
}
int main( )
{
Array_max<int> arrmax_int; //定义对象arrmax_int,该对象中数组元素类型为整型
arrmax_int.set_value( ); //调用arrmax_int的set_value函数,向数组元素输入数值
cout<<arrmax_int.max_value( )<<endl; //调用arrmax_int的max_value函数,找出数组元素中的最大值
Array_max<double> arrmax_double; //定义对象arrmax_double,该对象中数组元素类型为双精度型
arrmax_double.set_value( ); //调用arrmax_double的set_value函数,向数组元素输入数值
cout<<arrmax_double.max_value( )<<endl; //调用arrmax_double的max_value函数,找出数组元素中的最大值
Array_max<char> arrmax_char; //定义对象arrmax_char,该对象中数组元素类型为字符型
arrmax_char.set_value( ); //调用arrmax_char的set_value函数,向数组元素输入数值
cout<<arrmax_char.max_value( )<<endl; //调用arrmax_char的max_value函数,找出数组元素中的最大值
Array_max<string> arrmax_string; //定义对象arrmax_string,该对象中数组元素类型为字符串型
arrmax_string.set_value( ); //调用arrmax_string的set_value函数,向数组元素输入数值
cout<<arrmax_string.max_value( )<<endl; //调用arrmax_string,的max_value函数,找出数组元素中的最大值
return 0;
}
#include <iostream>
#include <string>
using namespace std;
template <class T>
class Array_max //声明类模板
{
public: //以下3行为成员函数原型声明
void set_value( ); //对数组元素设置值
T max_value( ); //找出数组中的最大元素
private:
T array[10]; //T类型数组
T max; //max用来存放数组中的最大值
};
template<class T>
void Array_max<T>::set_value( )
{
int i;
for (i=0; i<10; i++)
cin>>array[i];
}
template<class T>
T Array_max<T>::max_value( )
{
int i;
max=array[0];
for (i=1; i<10; i++)
max=max<array[i]?array[i]:max;
return max;
}
int main( )
{
Array_max<int> arrmax_int; //定义对象arrmax_int,该对象中数组元素类型为整型
arrmax_int.set_value( ); //调用arrmax_int的set_value函数,向数组元素输入数值
cout<<arrmax_int.max_value( )<<endl; //调用arrmax_int的max_value函数,找出数组元素中的最大值 Array_max<double> arrmax_double; //定义对象arrmax_double,该对象中数组元素类型为双精度型
arrmax_double.set_value( ); //调用arrmax_double的set_value函数,向数组元素输入数值
cout<<arrmax_double.max_value( )<<endl; //调用arrmax_double的max_value函数,找出数组元素中的最大值 Array_max<char> arrmax_char; //定义对象arrmax_char,该对象中数组元素类型为字符型
arrmax_char.set_value( ); //调用arrmax_char的set_value函数,向数组元素输入数值
cout<<arrmax_char.max_value( )<<endl; //调用arrmax_char的max_value函数,找出数组元素中的最大值 Array_max<string> arrmax_string; //定义对象arrmax_string,该对象中数组元素类型为字符串型
arrmax_string.set_value( ); //调用arrmax_string的set_value函数,向数组元素输入数值
cout<<arrmax_string.max_value( )<<endl; //调用arrmax_string,的max_value函数,找出数组元素中的最大值 return 0;
}
YTU 2642: 填空题:类模板---求数组的最大值的更多相关文章
- js求数组的最大值--奇技淫巧和笨方法
写这篇文章的原因 我目前做的项目很少用到算法,于是这方面的东西自然就有点儿生疏.最近的一次编码中遇到了从数组中获取最大值的需求,当时我不自觉的想到了js的sort()函数,现在想来真是有些“罪过”,当 ...
- c# 求数组的最大值
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- YTU 2641: 填空题:静态成员---计算学生个数
2641: 填空题:静态成员---计算学生个数 时间限制: 1 Sec 内存限制: 128 MB 提交: 267 解决: 206 题目描述 学生类声明已经给出,在主程序中根据输入信息输出实际建立的 ...
- C++基础 (9) 第九天 编译器对模板类的二次编译 类模板 自定义数组类
1 昨日回顾 2 编译器对于模板的二次编译 写一个模板函数 然后进行调用 g++ template.cpp -o template // 汇编 g++ -S template.cpp –o templ ...
- YTU 2586: 填空题B-字画鉴别
2586: 填空题B-字画鉴别 时间限制: 1 Sec 内存限制: 128 MB 提交: 509 解决: 131 题目描述 注:本题只需要提交填写部分的代码,请按照C语言方式提交. 古玩店老板小勇 ...
- YTU 2579: 填空题----删除指定字符
2579: 填空题----删除指定字符 时间限制: 1 Sec 内存限制: 128 MB 提交: 164 解决: 61 题目描述 小明想要做个小程序,能够删除字符串中特定的字符. 例如:想要在下面 ...
- 使用JavaScript·求数组的最大值和最小值
前言 在数组中并没有提供arr.max()和arr.min()这样的方法.那么是不是可以通过别的方式实现类似这样的方法呢?那么今天我们就来整理取出数组中最大值和最小值的一些方法. 法一:其实利用 ...
- 【RMQ问题】求数组区间最大值,NYOJ-1185-最大最小值
转自:http://blog.csdn.net/lilongherolilong/article/details/6624390 先挖好坑,明天该去郑轻找虐 RMQ(Range Minimum/Max ...
- 求数组的最小数、最大值,求一组数的平均数,sort函数详解,类数组转数组
求数组的最小值和最大值 //求数组当中最大值和最小值 var arr=[3,2,6,1,45,23,456,23,2,6,3,45,37,89,30]; //第一种方法 根据排序方法来求最大值和最小值 ...
随机推荐
- Java使用JNA方式调用DLL(动态链接库)(原创,装载请注明出处)
Java使用JNA调用DLL 1.准备 1.JDK环境 2.Eclipse 3.JNA包 下载JNA包: (1).JNA的Github:https://github.com/java-native-a ...
- CF508E Arthur and Brackets
题目大意:给出n对括号,并给出每对括号距离的范围.问能否找到这样一个序列. 题解:好多人都用贪心.这么好的题为什么不搜一发呢? 注意:千万不要在dfs里面更新答案. 代码: #include<c ...
- [BZOJ] 1037 [ZJOI2008]生日聚会
Time Limit: 10 Sec Memory Limit: 162 MB Submit: 3007 Solved: 1795 [Submit][Status][Discuss] Descript ...
- IO之DataStream数据流举例
import java.io.*; public class TestDataStream { public static void main(String[] args) { ByteArrayOu ...
- Ubuntu终端常用快捷键汇总
Ubuntu终端常用的快捷键 - 转自- 博客园 http://www.cnblogs.com/nucdy/p/5251659.html Ubuntu中的许多操作在终端(Terminal)中十分 ...
- nginx虚拟主机配置实践
1.配置基于域名的虚拟主机 [root@web01 html]# egrep -v "#|^$" /application/nginx/conf/nginx.conf.defaul ...
- Python之购物车
Python之购物车 msg_list = [ ['iphone',8888], ['coffe',38], ['book',90], ['Tesla',100000], ['RR',10000000 ...
- LeetCode (45) Jump Game II
题目 Given an array of non-negative integers, you are initially positioned at the first index of the a ...
- 集训第四周(高效算法设计)C题 (二分查找优化题)
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- 2017 GDCPC 省赛总结
第一年参加省赛,也是我接触acm半年多的第一个正式省级赛事,这半年来我为acm付出的可能很多,但经历过这次省赛后,给我唯一的感觉就是,还不够多. 直接分析题目吧,开始拿到试题后我读的是A题,然后我的队 ...