首页 > 其他分享 >PTA练习题

PTA练习题

时间:2023-05-07 20:56:42浏览次数:38  
标签:练习题 ch int cin PTA Time d2 d1

  1 #include<iostream>
  2 using namespace std;
  3 class Time
  4 {
  5     private:
  6         int hh;
  7         int mm;
  8         int ss;
  9     public:
 10         Time()
 11         {
 12             hh = 0;
 13             mm = 0;
 14             ss = 0;
 15         }
 16         void set(int h,int m,int s)
 17         {
 18             hh=h;
 19             mm=m;
 20             ss=s;
 21         }
 22         friend bool operator >(Time &t1,Time &t2);
 23         friend ostream & operator <<(ostream &,Time &);
 24 } ;
 25 bool operator >(Time &t1,Time &t2)
 26 {
 27     int re1=t1.hh*3600+t1.mm*60+t1.ss;
 28     int re2=t2.hh*3600+t2.mm*60+t2.ss;
 29     if(re1>re2)
 30     {
 31         return true;
 32     }
 33     else
 34     {
 35         return false;
 36     }
 37 }
 38  
 39 ostream &operator <<(ostream &output,Time&t)
 40 {
 41     output<<t.hh<<" "<<t.mm<<" "<<t.ss;
 42     return output;
 43 }
 44  
 45 class date
 46 {
 47     private:
 48         int year;
 49         int month;
 50         int day;
 51     public:
 52         date()
 53         {
 54             year = 0;
 55             month = 0;
 56             day = 0;
 57         }
 58         void set(int y,int m,int d)
 59         {
 60             year=y;
 61             month=m;
 62             day=d;
 63         }
 64         friend bool operator >(date &d1,date &d2);
 65         friend ostream & operator <<(ostream &,date &);
 66 };
 67  
 68 bool operator >(date &d1,date &d2)
 69 {
 70     int re1=d1.year*365+d1.month*30+d1.day;
 71     int re2=d2.year*365+d2.month*30+d2.day;
 72     if(re1>re2)
 73     {
 74         return true;
 75     }
 76     else
 77     {
 78         return false;
 79     }
 80 }
 81  
 82 ostream & operator <<(ostream &output,date &d)
 83 {
 84     output<<d.year<<" "<<d.month<<" "<<d.day;
 85     return output;
 86 }
 87  
 88 template <class T>
 89 T maxn(T x[], int len)
 90 {
 91     T max;
 92     max=x[0];
 93     for(int i=0; i<len; i++)
 94     {
 95         if(x[i]>max)
 96         {
 97             max=x[i];
 98         }
 99     }
100     cout<<max<<endl;
101     return max;
102 }
103  
104 int main()
105 {
106     int intArray[100];
107  
108     double douArray[100];
109     Time TimeArray[100];
110     date dateArray[100];
111     int ch;
112     int i=0;
113     while(cin>>ch)
114     {
115         if(ch==-1)
116         {
117             break;
118         }
119         if(ch==1)
120         {
121             while(cin>>intArray[i])
122             {
123                 if(intArray[i]==0)
124                 {
125                     break;
126                 }
127                 i++;
128             }
129             maxn(intArray,i);
130         }
131         if(ch==2)
132         {
133             while(cin>>douArray[i])
134             {
135                 if(douArray[i]==0)
136                 {
137                     break;
138                 }
139                 i++;
140             }
141             maxn(douArray,i);
142         }
143         if(ch==3)
144         {
145             int hour,minute,second;
146             while(cin>>hour)
147             {
148                 if(hour==0)
149                 {
150                     break;
151                 }
152                 cin>>minute>>second;
153                 TimeArray[i].set(hour,minute,second);
154                 i++;
155             }
156             maxn(TimeArray,i);
157         }
158         if(ch==4)
159         {
160             int years,months,days;
161  
162             while(cin>>years)
163             {
164                 if(years==0)
165                 {
166                     break;
167                 }
168                 cin>>months>>days;
169                 dateArray[i].set(years,months,days);
170                 i++;
171             }
172             maxn(dateArray,i);
173         }
174     }
175     return 0;
176 }

 

标签:练习题,ch,int,cin,PTA,Time,d2,d1
From: https://www.cnblogs.com/Lyh3012648079/p/17380124.html

相关文章

  • PTA练习题
    复数类Complex有两个数据成员:a和b,分别代表复数的实部和虚部,并有若干构造函数和一个重载-(减号,用于计算两个复数的距离)的成员函数。要求设计一个函数模板template<classT>doubledist(Ta,Tb)对int,float,Complex或者其他类型的数据,返回两个数据的间距。以上类名和函数模......
  • pta_【CPP0026】以点类Point及平面图形类Plane为基础设计三角形类Triangle
    #include<iostream>#include<cmath>usingnamespacestd;//点类PointclassPoint{private:doublex;doubley;public:Point(doublexv=0,doubleyv=0);/*构造函数*/Point(constPoint&p);/*拷贝构造*/~Point();/*......
  • pta实验报告2
    模板与类(对象数组)#include<bits/stdc++.h>usingnamespacestd;template<classT>Tmaxn(Tx[],intlen){ inti=1; Tmax=x[0]; for(i;i<len;i++) { if(max<x[i]) max=x[i]; } returnmax;}classDate{ private: intyear=0,month=0,day=0; public: Date()......
  • pta实验报告
    实验一:复数类及函数模板(switch语句)#include<bits/stdc++.h>usingnamespacestd;classComplex{private: inta,b; public: Complex(int_a,int_b):a(_a),b(_b){}; doubleoperator-(Complexn) { returnsqrt((a-n.a)*(a-n.a)+(b-n.b)*(b-n.b)); } ~Complex(){};......
  • C++/PTA 函数重载(数据类型不同)
    题目要求用同一个函数名对n(n<=10)个数据进行从小到大排序,数据类型可以是整数、浮点数,用函数重载实现。输入格式:输入n例如3输入n个整数,例如1089输入n个浮点数例如10.235.167.99输出格式:输出n个整数的升序排列:8910以空格间隔,并以空格结尾换行,输出n个浮点数的升......
  • 迁移学习(VMT)《Virtual Mixup Training for Unsupervised Domain Adaptation》
    论文信息论文标题:VirtualMixupTrainingforUnsupervisedDomainAdaptation论文作者:TakeruMiyato,S.Maeda,MasanoriKoyama,S.Ishii论文来源:2019CVPR论文地址:download 论文代码:download视屏讲解:click   ......
  • PTA题目集4~6总结Blog
    1.4~6题目集的大体总结第四次题目集的整体难度还是比较低的,第一题难度最大,放在后面说。第2,3题则涉及对重复数字的处理问题,本意是想要用双重循环解决问题结果运行超时,这也是我第一次学习hash表来解决问题,第4题则需相对更复杂一点,不仅需要对单词进行切割还要按指定规则进行排序,其......
  • PTA 4 - 6 总结
    1、前言这是第二次作业的博客总结,这次主要是在上次作业的基础上加大了难度,考验了我们写代码和自主学习的能力。    04:这次题目集主要学习了:使用LinkedHashSet删除arraylist中的重复数据,封装,了解Scanner类中nextLine()等方法、String类中split()等方法、Integer类中parse......
  • OOP PTA题目集4-6总结
    一、前言距离第一次做题目集总结已经过去了一个月,在这一个月里,我通过写题目又学到了许多新的知识。这一次题目集的难度比上一次的要难,考察的知识更多,也很考察设计能力与逻辑思维能力。题目集4总共7道题,题量适中,除了第一题外难度也适中。考察的内容主要有基础的语法、算法,还有......
  • PTA OOP训练集4-6总结
     一、前言二、设计与分析三、踩坑心得四、改进建议五、总结 南昌航空大学软件学院2201108郭海涛一、前言    OOP4-6次题目集,较前三次,知识点覆盖的范围更加广,难度也骤然上升,尤其是第六次题目集,从第三题开始就没有类图了,需要我们自行根据题目的需求和输入输出来设......