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. /proc/meminfo

    /proc/meminfo  可以查看自己服务器 物理内存 注意这个文件显示的单位是kB而不是KB,1kB=1000B,但是实际上应该是KB,1KB=1024B 这个显示是不精确的,是一个已知的没有被 ...

  2. Tensorflow(二)

    1---------------- 试用tensorflow的模块,必须配套tensorflow的方法 import tensorflow as tf a=3 ##定义 行向量 w=tf.Variab ...

  3. [py]django表单不清空实现的2种方法

    参考 参考: django实现内容不清空2种方法 django form的作用 1.生成html标签 2.验证输入内容 form生成表单 zhuji/forms.py - 实例化表单 - 定制form ...

  4. eclipse向svn提交代码的时候忽略部分资源配置

    eclipse向svn提交代码的时候有 .settings, .project, .classpath, target等不需要上传,所以在eclipse中配置一下就不会显示了,方法如下图:

  5. .Net Core 使用依赖注入

    ASP.NET Core 源码阅读笔记(1) ---Microsoft.Extensions.DependencyInjection 在asp .net中使用依赖注入很简单,只需要在Startup类的 ...

  6. WebService之Axis2(1):用POJO实现0配置的WebService

    Axis2是一套崭新的WebService引擎,该版本是对Axis1.x重新设计的产物.Axis2不仅支持SOAP1.1和SOAP1.2,还集成了非常流行的REST WebService,同时还支持S ...

  7. Approximate Inference

    1.  Approximation    Probabilistic model  中的一个 central task :给定一组observation X 后,计算latent variables ...

  8. CentOS6.5安装Twemproxy集群

    Twemproxy,也叫Nutcraker.是一个Twtter开源的一个Redis和Memcache代理服务器. Redis作为一个高效的缓存服务器,非常具有应用价值.但是当使用比较多的时候,就希望可 ...

  9. 7.8 Models -- The Rest Adapter

    一.概述 默认的,store将会使用 DS.RESTAdapter来加载和存储records.这个RESTAdapter假定URLS和JSON关联每一个model是约定好的:这意味着,如果你遵循这个规 ...

  10. OpenStack trove原理及配置实践

    DBaaS是什么? 字面上理解数据库即是服务,简单来说就是以服务的形式为用户提供数据库服务. 在云平台上使用trove有什么优势? 简化IT操作流程,降低使用数据库使用门槛举个例子,曾经我搭建一个LA ...