5-1

#include <iostream>
#include <cstdlib>
#include <string.h>
using namespace std; class polygon
{
protected:
int number;
private:
int side_length[100];
public:
polygon(int a = 0):number(a){memset(side_length, 0, sizeof(side_length));};
int perimeter();//计算多边形边长
void display();//输出多边形边数和周长
int* reachsidelen();
}; int polygon::perimeter()
{
int i;
int tot = 0;
for (i = 1; i <= number; i++)
{
tot += side_length[i];
} return tot;
} void polygon::display()
{
cout << number << " " << perimeter() << endl;
} int* polygon::reachsidelen()
{
return side_length;
} class rectangle : protected polygon
{
protected:
int height;
int width;
public:
rectangle(int a = 0, int b = 0, int c = 0):polygon(a), height(b), width(c){};
int perimeter();//计算矩形边长
void display();//输出多边形边数和周长
}; int rectangle::perimeter()
{
int tot = 0;
tot = height * 2 + width * 2;
return tot;
} void rectangle::display()
{
cout << number << " " << perimeter() << endl;
} class equal_polygon : protected polygon
{
protected:
int side_len;
public:
equal_polygon(int a = 0, int b = 0):polygon(a), side_len(b){};
int perimeter();//计算等边多边形边长
void display();//输出多边形边数和周长
}; int equal_polygon::perimeter()
{
int tot = 0;
tot = number * side_len;
return tot;
} void equal_polygon::display()
{
cout << number << " " << perimeter() << endl;
} int main()
{
int b[105];
int i,j; int cnt = 0;
cin >> cnt; int ope;
while(cnt --)
{
memset(b, 0, sizeof(b)); cin >> ope;
if(ope == 0)
{
int tot = 1;
int idata;
while(cin >> idata)
{
if(idata == -1)break; b[tot++] = idata;
}
tot --; polygon P(tot);
int *p = P.reachsidelen(); for (i = 1; i <= tot; i++)
{
*(p + i) = b[i];
} P.display();
}
else if(ope == 1)
{
int iwide, ilen;
cin >> iwide >> ilen;
rectangle R(4, ilen, iwide);
R.display();
}
else if(ope == 2)
{
int inumber, ilen;
cin >> inumber >> ilen;
equal_polygon E(inumber, ilen);
E.display();
}
} return 0;
}

5-2

#include <iostream>
#include <stdlib.h>
#include <cmath>
using namespace std; class Point_1D
{
protected:
float x;//1D 点的x坐标
public:
Point_1D(float a = 0): x(a){}; float distance( );//计算当前点到原点的距离
}; float Point_1D::distance()
{
float d = x;
if(d < 0) d = -d;
return d;
} class Point_2D : protected Point_1D
{
protected:
float y;
public:
Point_2D(float a = 0, float b = 0): Point_1D(a), y(b){};
float distance( );
}; float Point_2D::distance()
{
float d;
d = sqrt(x * x + y * y);
return d;
} class Point_3D : protected Point_2D
{
protected:
float z;
public:
Point_3D(float a = 0, float b = 0, float c = 0): Point_2D(a, b), z(c){};
float distance( );
}; float Point_3D::distance()
{
float d;
d = sqrt(x * x + y * y + z * z);
return d;
} int main()
{
int ope;
while(cin >> ope)
{
if(ope == 0)break;
if(ope == 1)
{
float ix;
cin >> ix;
Point_1D p1(ix); cout << "Distance from Point " << ix << " to original point is "
<< p1.distance() << endl;
}
else if(ope == 2)
{
float ix, iy;
cin >> ix >> iy;
Point_2D p2(ix, iy); cout << "Distance from Point(" << ix << "," << iy
<< ") to original point is " << p2.distance() << endl;;
}
else if(ope == 3)
{
float ix, iy, iz;
cin >> ix >> iy >> iz;
Point_3D p3(ix, iy, iz); cout << "Distance from Point(" << ix << "," << iy << "," << iz
<< ") to original point is " << p3.distance() << endl;;
}
}
return 0;
}

5-3

用了sstream,主函数太长了。。

#include <iostream>
#include <cstdlib>
#include <sstream>
using namespace std; class Date
{
protected:
int year;
int month;
int day;
public:
Date(int a = 0, int b = 0, int c = 0):year(a), month(b), day(c){};
}; class Time
{
protected:
int hour;
int minute;
int second;
public:
Time(int a = 0, int b = 0, int c = 0):hour(a), minute(b), second(c){};
}; class Schedule : protected Date, protected Time
{
protected:
int ID;
public:
Schedule(int y = 10000, int m = 0, int d = 0, int h = 0, int min = 0, int s = 0, int id = 0):
Date(y, m, d), Time(h, min, s), ID(id){}; bool operator < (const Schedule & s2); void display();
}; void Schedule::display() //The urgent schedule is No.1: 2014/6/27 8:0:1
{
cout << ID << ": " << year << "/" << month << "/" << day << " " << hour
<< ":" << minute << ":" << second << endl;
} bool Schedule::operator < (const Schedule & s2)
{
int dtot1 = 0, tot1 = 0;
int dtot2 = 0, tot2 = 0;
dtot1 = year * 365 + month * 30 + day;
dtot2 = s2.year * 365 + s2.month * 30 + s2.day; tot1 = hour * 3600 + minute * 60 + second;
tot2 = s2.hour * 3600 + s2.minute * 60 + s2.second; if(dtot1 < dtot2)return true;
else if(dtot1 > dtot2)return false;
else
{
if(tot1 < tot2)return true;
else return false;
}
} int main()
{
int id;
int i;
int record;
Schedule sch; while(cin >> id)
{
if(id == 0)break; string date, time;
cin >> date >> time; stringstream stream;
string s1, s2; int y = 0, m = 0, d = 0, h = 0, min = 0, s = 0;
bool flag = false;
for(i = 0; i < date.length(); i++)
{
if(date[i] == '/')
{
if(flag)
{
stream << s1;
stream >> m;
stream.clear();
s1 = "";
}
else
{
stream << s1;
stream >> y;
stream.clear(); s1 = "";
flag = true;
}
}
else
s1 += date[i];
}
stream << s1;
stream >> d;
stream.clear(); bool flag2 = false; for(i = 0; i < time.length(); i++)
{
if(time[i] == ':')
{
if(flag2)
{
stream << s2;
stream >> min;
stream.clear();
s2 = "";
}
else
{
stream << s2;
stream >> h;
stream.clear();
s2 = ""; flag2 = true;
}
}
else
s2 += time[i];
}
stream << s2;
stream >> s;
stream.clear(); Schedule sch1(y, m, d, h, min, s, id);
if(sch1 < sch)sch = sch1;
} cout << "The urgent schedule is No.";
sch.display();
return 0;
}

PTA第三次上机的更多相关文章

  1. 17秋 SDN课程 第三次上机作业

    SDN 第三次上机作业 1.创建拓扑 2.利用OVS命令下发流表,实现vlan功能 3.利用OVS命令查看流表 s1: s2: 4.验证性测试 5.Wireshark 抓包验证

  2. SDN 第三次上机作业

    SDN 第三次上机作业 1.创建拓扑 2.利用OVS命令下发流表,实现vlan功能 3.利用OVS命令查看流表 s1: s2: 4.验证性测试 5.Wireshark 抓包验证

  3. 『嗨威说』算法设计与分析 - PTA 数字三角形 / 最大子段和 / 编辑距离问题(第三章上机实践报告)

    本文索引目录: 一.PTA实验报告题1 : 数字三角形 1.1 实践题目 1.2 问题描述 1.3 算法描述 1.4 算法时间及空间复杂度分析 二.PTA实验报告题2 : 最大子段和 2.1 实践题目 ...

  4. Java第三次上机随笔

    就记录一下新的收获吧~ 1.定点数(BigDecimal) 先区分一下浮点数和定点数: 浮点数(float/double):小数点可以任意浮动,称为浮点表示法 定点数(BigDecimal):一种数约 ...

  5. PTA第三次作业

    ---恢复内容开始--- 题目 7-1 计算职工工资 1.设计思路 (1)第一步:观察题意了解各个参数与所需函数在题目中的意义: 第二步:设计算法编写函数,让函数的功能实现题目中所需的功能: 第三步: ...

  6. PTA第三个编程题总结

    7-1 抓老鼠啊~亏了还是赚了? (20 分) 某地老鼠成灾,现悬赏抓老鼠,每抓到一只奖励10元,于是开始跟老鼠斗智斗勇:每天在墙角可选择以下三个操作:放置一个带有一块奶酪的捕鼠夹(T),或者放置一块 ...

  7. PTA寒假三

    抓老鼠啊~亏了还是赚了? (20 分) 某地老鼠成灾,现悬赏抓老鼠,每抓到一只奖励10元,于是开始跟老鼠斗智斗勇:每天在墙角可选择以下三个操作:放置一个带有一块奶酪的捕鼠夹(T),或者放置一块奶酪(C ...

  8. 2016级算法第三次上机-G.Winter is coming

    904 Winter is coming 思路 难题.首先简化问题, \(n\) 个0与 \(m\) 个1排成一列,连续的0不能超过x个,连续的1不能超过y个,求排列方法数. 显然会想到这是动态规划. ...

  9. 2016级算法第三次上机-C.AlvinZH的奇幻猜想——三次方

    905 AlvinZH的奇幻猜想--三次方 思路 中等题.题意简单,题目说得简单,把一个数分成多个立方数的和,问最小立方数个数. 脑子转得快的马上想到贪心,从最近的三次方数往下减,反正有1^3在最后撑 ...

随机推荐

  1. spring 装配集合

    1:创建pojo,属性包含集合,集合元素为基本类型 package com.liyafei.pojo; import java.util.List; import java.util.Map; imp ...

  2. Liferay中request

    在liferay中的请求分为renderRequest和actionRequest这两种请求的方式,portletRequest的子类有三个1renderRequest,2EventRequest3C ...

  3. vue 渲染页面的时候 出现闪烁问题的解决办法

    在使用vue绑定数据的时候,渲染页面时会出现变量闪烁 <div id="h_cameraman" v-cloak> <public-nav> {{ msg ...

  4. 大杀器Bodymovin和Lottie:把AE动画转换成HTML5/Android/iOS原生动画

    前段时间听部门老大说,Airbnb出了个移动端的动画库Lottie,可以和一个名叫Bodymovin的AE插件结合起来,把在AE上做好的动画导出为json文件,然后以Android/iOS原生动画的形 ...

  5. python管道pipe,两个进程,使用管道的两端分别执行写文件动作,带锁(lock)

    #coding=utf-8import multiprocessing as mp def write_file(content,lock):    lock.acquire()    with op ...

  6. Python中文件的读写操作的几种方法

    对文件的操作,步骤为:打开一个文件-->读取/写入内容-->保存文件 文件读写的3中模式 # 1.w 写模式,它是不能读的,如果用w模式打开一个已经存在的文件,会清空以前的文件内容,重新写 ...

  7. 怎样将一个整数转化成字符串数,并且不用函数itoa

    #include<iostream> using namespace std; int main() { , j = , i = ; ], str[]; while (num) { tem ...

  8. P3366 【模板】最小生成树(堆优化prim)

    堆优化prim #include<cstdio> #include<cstring> #include<queue> using namespace std; st ...

  9. 移动页面click延迟引发的touch问题

    一.事件捕获与冒泡 先扯一下事件的触发流程,这个之后会用到. DOM2级事件规定事件包括三个阶段: ① 事件捕获阶段 ② 处于目标阶段 ③ 事件冒泡阶段 大概的流程就是事件从最外层一层一层往里面传递( ...

  10. 使用fragment添加底部导航栏

    切记:fragment一定要放在framlayout中,不然不会被替换完全(就是切换之后原来的fagment可能还会存在) main.xml <LinearLayout xmlns:androi ...