PTA fzu_oop_east
GitHub链接: 传送门
5-1该日是该年的第几天
定义一个日期类Date,内有数据成员年、月、日,另有成员函数:构造函数用于初始化数据成员,输出,闰年的判断。 编写主函数:创建日期对象,计算并输出该日是该年的第几天。 输入格式: 测试输入包含若干测试用例,每个测试用例占一行。当读入0 0 0时输入结束,相应的结果不要输出。
输入样例:
2006 3 5
2000 3 5
0 0 0
输出样例:(括号内为说明)
64 (2006年3月5日是该年的第64天)
65 (2000年3月5日是该年的第65天)
#include<iostream>
#include<cstdio>
using namespace std;
class Data{
private:
int year,month,day;
public:
Data();
bool IsLeap(int year);
void set(int x,int y,int z);
int TheDay(int Year,int Month,int Day);
void Print(int Day);
};
Data::Data()
{
year = 0;
month = 0;
day = 0;
}
bool Data::IsLeap(int year)
{
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
{
return true;
}
else
{
return false;
}
}
void Data::set(int x,int y,int z)
{
year = x;
month = y;
day = z;
}
int Data::TheDay(int Year,int Month,int Day)
{
int ans[13] = {0,0,31,59,90,120,151,181,212,243,273,304,334};
Day += ans[Month];
if (IsLeap(Year))
{
if (Month > 2)
{
Day++;
}
}
return Day;
}
void Data::Print(int Day)
{
printf("%d\n",Day);
}
int main()
{
int Year,Month,Day;
Data Calender;
while (~scanf("%d %d %d",&Year,&Month,&Day) && Year && Month && Day)
{
Calender.set(Year,Month,Day);
Day = Calender.TheDay(Year,Month,Day);
Calender.Print(Day);
}
return 0;
}
5-2宿舍谁最高?
学校选拔篮球队员,每间宿舍最多有4个人。现给出宿舍列表,请找出每个宿舍最高的同学。定义一个学生类Student,有私有成员身高height,体重weight等。
输入格式:
首先输入一个整型数n (1<=n<=1000000),表示n位同学。
紧跟着n行输入,每一行格式为:宿舍号,name,height,weight。
宿舍号的区间为[0,999999], name 由字母组成,长度小于16,height,weight为正整数。
输出格式:
按宿舍号从小到大排序,输出每间宿舍身高最高的同学信息。题目保证每间宿舍只有一位身高最高的同学。
输入样例:
7
000000 Tom 175 120
000001 Jack 180 130
000001 Hale 160 140
000000 Marry 160 120
000000 Jerry 165 110
000003 ETAF 183 145
000001 Mickey 170 115
输出样例:
000000 Tom 175 120
000001 Jack 180 130
000003 ETAF 183 145
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include <iomanip>
using namespace std;
class Student
{
private:
int height;
int weight;
string name;
public:
void memset();
void set(int h,int w,string ne);
void cmp(int h,int w,string ne);
void print();
};
void Student::set(int h,int w,string ne)
{
height = h;
weight = w;
name = ne;
}
void Student::memset()
{
height = -1;
weight = -1;
}
void Student::cmp(int h,int w,string ne)
{
if (h > height)
{
set(h,w,ne);
}
}
void Student::print()
{
cout << name << " " << height << " " << weight << endl;
}
Student stu[1000005];
int cnt[1000005];
int main()
{
int N;
for (int i = 0;i < 1000000;i++)
{
stu[i].memset();
}
scanf("%d",&N);
int h,w,roomnum;
string ne;
for (int i = 0;i < N;i++)
{
cin >> roomnum >> ne >> h >> w;
stu[roomnum].cmp(h,w,ne);
cnt[i] = roomnum;
}
sort(cnt,cnt + N);
for (int i = 0;i < N;)
{
while (cnt[i] == cnt[i + 1])
{
i++;
}
cout << setfill('0') << setw(6) << cnt[i] << " ";
stu[cnt[i++]].print();
}
}
5-3 范围内约数最多的数
给定任意一个整数,可以找出这个数的所有约数,如6,它有1、2、3、6一共4个约数。
我们会给出一个整数范围,需要你找出这个范围内的整数中,约数最多的那个数,并输出这个数的所有约数。
输入格式:
输入只有一行,共两个正整数F,T其中1<=F<=T<=100000。
输出格式:
输出有两行。
第一行由三部分组成:第一部分是“[F,T]”;第二部分是区间范围内有最多约数的那个数;第三部分是约数的个数。三部分之间用一个空格隔开,行尾没有空格。
第二行是对应的约数,从小到大排列,中间用一个空格隔开,末尾没有空格。
当符合要求的答案不唯一时,输出有最多约数时本身数最小的那个。
输入样例:
3 10
输出样例:
[3,10] 6 4
1 2 3 6
#include<iostream>
#include<set>
#include<map>
#include<cstdio>
#include<cmath>
using namespace std;
int Factor(int N)
{
set<int>all;
int max = sqrt(N);
for (int i = 1;i <= max;i++)
{
if (N % i == 0)
{
all.insert(i);
all.insert(N/i);
}
}
int len = all.size();
return len;
}
int main()
{
int F,T,num,max = 0;
set<int>all;
set<int>::iterator it;
scanf("%d%d",&F,&T);
for (int i = F;i <= T;i++)
{
int len = Factor(i);
if (max < len)
{
num = i;
max = len;
}
else if (max == len && i < num)
{
num = i;
max = len;
}
}
max = sqrt(num);
for (int i = 1;i <= max;i++)
{
if (num % i == 0)
{
all.insert(i);
all.insert(num/i);
}
}
printf("[%d,%d] %d %d\n",F,T,num,all.size());
bool first = true;
for (it = all.begin();it != all.end();it++)
{
first?printf("%d",*it):printf(" %d",*it);
first = false;
}
return 0;
}
5-4 单向链表1
链表节点定义为: struct Node{ int data; struct Node *next; }
编程实现:输入一个正整数 repeat (0<repeat<10),做 repeat 次下列运算: 输入若干个正整数(输入-1为结束标志),建立一个单向链表,将其中的奇数值结点删除后输出
输入输出示例:括号内为说明
输入样例:
2 (repeat=2)
1 2 3 4 5 6 7 -1
1 3 5 -1
输出样例:
2 4 6
#include<stdio.h>
#include<stdlib.h>
struct Node{
int data;
struct Node *next;
};
struct Node *Init()
{
struct Node *current,*prev;
struct Node *head = NULL;
current = (struct Node *)malloc(sizeof(struct Node));
scanf("%d",¤t->data);
while (current->data != -1)
{
if (current->data % 2 != 0)
{
current = (struct Node *)malloc(sizeof(struct Node));
scanf("%d",¤t->data);
continue;
}
if (head == NULL)
{
head = current;
}
else
{
prev->next = current;
}
prev = current;
prev->next = NULL;
current = (struct Node *)malloc(sizeof(struct Node));
scanf("%d",¤t->data);
}
return head;
}
void Print(struct Node *head)
{
bool first = true;
bool empty = true;
struct Node *current = head;
while (current != NULL)
{
first?printf("%d",current->data):printf(" %d",current->data);
first = false;
empty = false;
current = current->next;
}
if (!empty)
{
printf("\n");
}
}
void Free(struct Node *head)
{
struct Node *current,*tmp;
current = head;
while (current != NULL)
{
tmp = current->next;
free(current);
current = tmp;
}
}
int main()
{
struct Node *head = NULL;
int repeat;
scanf("%d",&repeat);
while (repeat--)
{
head = Init();
Print(head);
Free(head);
}
return 0;
}
5-5 链表操作2
编程实现:输入若干个正整数(输入-1为结束标志),建立一个单向链表,将其中的偶数值结点删除后输出。链表节点定义为: struct Node{ int data; struct Node *next; }
输入输出示例:括号内为说明
输入样例:
1 2 3 4 5 6 7 -1
输出样例:
1 3 5 7
#include<stdio.h>
#include<stdlib.h>
struct Node{
int data;
struct Node *next;
};
struct Node *Init()
{
struct Node *current,*prev;
struct Node *head = NULL;
current = (struct Node *)malloc(sizeof(struct Node));
scanf("%d",¤t->data);
while (current->data != -1)
{
if (current->data % 2 == 0)
{
current = (struct Node *)malloc(sizeof(struct Node));
scanf("%d",¤t->data);
continue;
}
if (head == NULL)
{
head = current;
}
else
{
prev->next = current;
}
prev = current;
prev->next = NULL;
current = (struct Node *)malloc(sizeof(struct Node));
scanf("%d",¤t->data);
}
return head;
}
void Print(struct Node *head)
{
bool first = true;
bool empty = true;
struct Node *current = head;
while (current != NULL)
{
first?printf("%d",current->data):printf(" %d",current->data);
first = false;
empty = false;
current = current->next;
}
if (!empty)
{
printf("\n");
}
}
void Free(struct Node *head)
{
struct Node *current,*tmp;
current = head;
while (current != NULL)
{
tmp = current->next;
free(current);
current = tmp;
}
}
int main()
{
struct Node *head = NULL;
head = Init();
Print(head);
Free(head);
return 0;
}
PTA fzu_oop_east的更多相关文章
- 浙大PTA - - 堆中的路径
题目链接:https://pta.patest.cn/pta/test/1342/exam/4/question/21731 本题即考察最小堆的基本操作: #include "iostrea ...
- 浙大PTA - - File Transfer
题目链接:https://pta.patest.cn/pta/test/1342/exam/4/question/21732 #include "iostream" #includ ...
- ERROR<53761> - Plugins - conn=-1 op=-1 msgId=-1 - Connection Bind through PTA failed (91). Retrying...
LDAP6.3在DSCC控制台启动实例完成,但是操作状态显示“意外错误”,查看日志如下: 04/May/2016:21:10:39 +0800] - Sun-Java(tm)-System-Direc ...
- PTA中提交Java程序的一些套路
201708新版改版说明 PTA与2017年8月已升级成新版,域名改为https://pintia.cn/,官方建议使用Firefox与Chrome浏览器. 旧版 PTA 用户首次在新版系统登录时,请 ...
- PTA分享码-Java
主要用于Java语法练习,非竞赛类题目. 1. Java入门 959dbf0b7729daa61d379ec95fb8ddb0 2. Java基本语法 23bd8870e ...
- C语言第一次实验报告————PTA实验1.2.3内容
一.PTA实验作业 题目1.温度转换 本题要求编写程序,计算华氏温度100°F对应的摄氏温度.计算公式:C=5×(F−32)/9,式中:C表示摄氏温度,F表示华氏温度,输出数据要求为整型. 1.实验代 ...
- PTA题---求两个有序序列中位数所体现的思想。
---恢复内容开始--- 近日,在做PTA题目时,遇到了一个这样的题,困扰了很久.题目如下:已知有两个等长的非降序序列S1, S2, 设计函数求S1与S2并集的中位数.有序序列A0,A1, ...
- 第十四,十五周PTA作业
1.第十四周part1 7-3 #include<stdio.h> int main() { int n; scanf("%d",&n); int a[n]; ...
- 第七周PTA作业
第一题: #include<stdio.h> int main() { ; ; ){ sum=sum+i; i++; } printf("sum = %d\n",sum ...
随机推荐
- EMV内核使用中的常见问题
EMV内核在使用上会由于调用不当引起的许多问题,本文旨在基于内核LOG(也就是与IC卡交互的指令LOG)的基础上,对一些常见问题作初步的分析与解答,方便不熟悉EMV规范的同学参考. 本文的前提是你已经 ...
- Python2.3-原理之语句和语法
此节来自于<Python学习手册第四版>第三部分 一.python语句简介(第10章) 1.首先记得一个概念:a.程序由模块构成:b.模块包含语句:c.语句包含表达式:d.表达式建立并处理 ...
- Nodejs基础:路径处理模块path总结
模块概览 在nodejs中,path是个使用频率很高,但却让人又爱又恨的模块.部分因为文档说的不够清晰,部分因为接口的平台差异性. 将path的接口按照用途归类,仔细琢磨琢磨,也就没那么费解了. 获取 ...
- Vue学习笔记-2
前言 本文非vue教程,仅为学习vue过程中的个人理解与笔记,有说的不正确的地方欢迎指正讨论 1.computed计算属性函数中不能使用vm变量 在计算属性的函数中,不能使用Vue构造函数返回的vm变 ...
- flash
1. 1.这种方式已经比较旧了, 2. html.push('<div class="flash-ad" style = "position:relative&qu ...
- JavaScript学习笔记- 自定义滚动条插件
此滚动条仅支持竖向(Y轴) 一.Css /*这里是让用户鼠标在里面不能选中文字,避免拖动的时候出错*/ body { -moz-user-select: none; /*火狐*/ -webkit-us ...
- Webmin|Linux管理员远程管理工具
介绍: Webmin is a web-based interface for system administration for Unix. Using any modern web browser ...
- PHP -- 上传文件接口编写 及 iOS -- 端上传图片AF实现
PHP 上传文件接口: //保存图片 $json_result ['status'] = 0; $path = 'upfile'; $json_result ['status'] = 0; $json ...
- python代码缩进
习惯了java,c++之类的宽容,初学python,被它摆了道下马威,写if else,竟然必须要我正确用缩进格式,原来在python里不能用括号来表示语句块,也不能用开始/结束标志符来表示,而是靠缩 ...
- MediaWiki隐藏index
Apache 在httpd.conf配置文件中加载mod_rewrite.so模块,将前面的'#'去掉,如果没有则添加这句话: #LoadModule rewrite_module modules/m ...