5-5

#include <cstdio>
#include <iostream>
#include <cstdlib>
using namespace std; struct Node
{
int data;
Node *next;
}; int tot = 0; Node *Node_Creat()
{
Node *head;
head = (Node *)malloc(sizeof(Node));
if(head == NULL)
{
printf("Overflow\n");
exit(1);
} head = NULL; Node *p1,*p2;
p1 = (Node *)malloc(sizeof(Node));
if(p1 == NULL)
{
printf("Overflow\n");
exit(1);
}
scanf("%d",&p1 -> data); while(p1 -> data != -1)
{
if(p1 -> data % 2 == 0)
{
scanf("%d",&p1 -> data);
continue;
} tot++; if(head == NULL)
{
head = p1;
}
else
{
p2 -> next = p1;
} p2 = p1;
p1 = (Node *)malloc(sizeof(Node));
if(p1 == NULL)
{
printf("Overflow\n");
exit(1);
} scanf("%d",&p1 -> data);
}
p2 -> next = NULL; return head;
} void Node_Print(Node *head)
{
Node *p;
p = head; while(p -> next != NULL)
{
printf("%d ",p -> data);
p = p -> next;
} printf("%d",p -> data);
} //没有用到
Node *Node_Delete(Node *head,int num)
{
Node *p1,*p2; p1 = p2 = head; if(num == 1)
{
tot--;
head = head -> next;
return head;
} for(int i = 1; i < num; i++)
{
p2 = p1;
p1 = p1 -> next;
} p2 -> next = p1 -> next;
tot--; free(p1); return head;
} int main()
{
Node *head;
head = Node_Creat(); Node_Print(head); return 0;
}

5-4

#include <cstdio>
#include <iostream>
#include <cstdlib>
using namespace std; struct Node
{
int data;
Node *next;
}; int tot = 0; Node *Node_Creat()
{
Node *head;
head = (Node *)malloc(sizeof(Node));
if(head == NULL)
{
printf("Overflow\n");
exit(1);
} head = NULL; Node *p1,*p2;
p1 = (Node *)malloc(sizeof(Node));
if(p1 == NULL)
{
printf("Overflow\n");
exit(1);
}
scanf("%d",&p1 -> data); while(p1 -> data != -1)
{
if(p1 -> data % 2 == 1)
{
scanf("%d",&p1 -> data);
continue;
} tot++; if(head == NULL)
{
head = p1;
}
else
{
p2 -> next = p1;
} p2 = p1;
p1 = (Node *)malloc(sizeof(Node));
if(p1 == NULL)
{
printf("Overflow\n");
exit(1);
} scanf("%d",&p1 -> data);
}
p2 -> next = NULL; return head;
} void Node_Print(Node *head)
{
Node *p;
p = head; if(head == NULL)return ; while(p -> next != NULL)
{
printf("%d ",p -> data);
p = p -> next;
} printf("%d\n",p -> data);
} //还是没有用到
Node *Node_Delete(Node *head,int num)
{
Node *p1,*p2; p1 = p2 = head; if(num == 1)
{
tot--;
head = head -> next;
return head;
} for(int i = 1; i < num; i++)
{
p2 = p1;
p1 = p1 -> next;
} p2 -> next = p1 -> next;
tot--; free(p1); return head;
} int main()
{
Node *head; int repeat;
scanf("%d",&repeat);
int i,j; for(i = 1; i <= repeat; i++)
{
head = Node_Creat(); Node_Print(head);
} return 0;
}

5-3

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std; int store[1000005]; int s[1000005]; int main()
{
int i,j;
int l,r;
scanf("%d%d",&l,&r); int tot = l;
for(i = l; i <= r; i++)
{
for(j = 1; j <= sqrt(i); j++)
{
if(i % j == 0)store[i]++;
} if(sqrt(i) * sqrt(i) == i)
{
store[i] = store[i]*2 - 1;
}
else
{
store[i] *= 2;
} if(store[i] > store[tot])tot = i;
} printf("[%d,%d] %d ",l,r,tot); int cnt = 1;
for(i = 1; i <= tot; i++)
{
if(tot % i == 0)
{
s[cnt] = i;
cnt++;
}
} printf("%d\n",--cnt); for(i = 1; i <= cnt; i++)
{
if(i != cnt)
printf("%d ",s[i]);
else
printf("%d",s[i]);
} return 0;
}

5-2

分文件写法:

student.h

#ifndef STUDENT_H
#define STUDENT_H
#include <iostream>
#include <string>
using namespace std; class Student
{
private:
int height;
int weight;
public:
string name;
void creat();
void cmp(string cmpname,int h,int w);
void Print();
}; #endif // STUDENT_H

main.cpp

#include "student.h" // class's header file
#include <string>
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
using namespace std; Student stu[1000005]; void Student::creat()
{
if(height > 0)return ; height = 0;
weight = 0;
} void Student::cmp(string cmpname,int h,int w)
{
if(h > height)
{
height = h;
weight = w;
name = cmpname;
}
} void Student::Print()
{
cout << name << " " << height << " "<< weight << endl;
} int turn[1000005]; int main()
{
int i,j;
int n;
cin >> n;
int a,b,c;
string name; for(i = 1; i <= n; i++)
{
cin >> a; turn[i] = a; stu[a].creat(); cin >> name >> b >> c; stu[a].cmp(name,b,c);
} sort(turn+1,turn+n+1); int cnt = 0;
turn[0] = -1; for(i = 1; i <= n; i++)
{
if(turn[i] != turn[cnt])
{
cnt = i;
printf("%06d ",turn[i]);
stu[turn[i]].Print();
}
} return 0;
}
//比较懒,就直接把类中函数定义和主函数放一起了= =

单文件写法:

#include <string>
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
using namespace std; class Student
{
private:
int height;
int weight;
public:
string name;
void creat();
void cmp(string cmpname,int h,int w);
void Print();
}; Student stu[1000005]; void Student::creat()
{
if(height > 0)return ; height = 0;
weight = 0;
} void Student::cmp(string cmpname,int h,int w)
{
if(h > height)
{
height = h;
weight = w;
name = cmpname;
}
} void Student::Print()
{
cout << name << " " << height << " "<< weight << endl;
} int turn[1000005]; int main()
{
int i,j;
int n;
cin >> n;
int a,b,c;
string name; for(i = 1; i <= n; i++)
{
cin >> a; turn[i] = a; stu[a].creat(); cin >> name >> b >> c; stu[a].cmp(name,b,c);
} sort(turn+1,turn+n+1); int cnt = 0;
turn[0] = -1; for(i = 1; i <= n; i++)
{
if(turn[i] != turn[cnt])
{
cnt = i;
printf("%06d ",turn[i]);
stu[turn[i]].Print();
}
} return 0;
}

5-2 纯sort写法

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stdlib.h>
#include <string>
using namespace std; class P
{
private:
int height;
int weight;
public:
string name;
int norm;
int display();
void play();
void f(int nor,string nam,int h,int w);
}; void P::play()
{
cout << " " << height << " " << weight << endl;
} int P::display()
{
int a;
a = height;
return a;
} void P::f(int nor,string nam,int h,int w)
{
norm = nor;
name = nam;
height = h;
weight = w;
} P p[105]; bool cmp(P p1,P p2)
{
if(p1.norm != p2.norm)return p1.norm > p2.norm;
else if(p1.display() != p2.display())return p1.display() < p2.display();
} int main()
{
int n;
string nam;
int i,j;
int w,h;
int nor; scanf("%d",&n); for(i = 1; i <= n; i++)
{
cin >> nor >> nam >> h >> w;
p[i].f(nor,nam,h,w);
} sort(p+1,p+n+1,cmp); int tot = -1; for(i = n; i >= 1; i--)
{
if(p[i].norm != tot)
{
tot = p[i].norm; printf("%06d ",p[i].norm); cout << p[i].name; p[i].play();
}
} return 0;
}

5-1

分文件写法:

main.cpp

#include "date.h"
#include <iostream>
#include <stdlib.h>
#include <cstdio>
using namespace std; int main()
{
int year,mouth,day;
int i,j;
while(scanf("%d%d%d",&year,&mouth,&day) != EOF)
{
bool flag = true;
Date D; D.fun1();
D.fun2(year,mouth,day); flag = D.is_leap();
D.display(flag);
}
return 0;
}

date.h

#ifndef DATE_H
#define DATE_H
#include <iostream>
using namespace std; class Date
{
private :
int year;
int day;
int mouth;
public :
void fun1();
void fun2(int a,int b,int c);
void display(bool isleap);
bool is_leap();
//protected :
}; #endif // DATE_H

date.cpp

#include "date.h" // class's header file
#include <iostream>
#include <stdlib.h>
#include <cstdio>
using namespace std; int leap_year[15]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int nomal_year[15]={0,31,28,31,30,31,30,31,31,30,31,30,31}; void Date::fun1()
{
year = 0;
mouth = 0;
day = 0;
} void Date::fun2(int a,int b,int c)
{
year = a;
mouth = b;
day = c;
} void Date::display(bool isleap)
{
int i,j;
int tot = 0;
if(isleap)
{
for(i = 1; i <= mouth-1; i++)
{
tot += leap_year[i];
} tot += day; printf("%d\n",tot);
}
else
{
for(i = 1; i <= mouth-1; i++)
{
tot += nomal_year[i];
} tot += day; printf("%d\n",tot);
}
} bool Date::is_leap()
{
if(year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
{
return true;
}
else return false;
}

单文件写法:

#include <iostream>
#include <stdlib.h>
#include <cstdio>
using namespace std; int leap_year[15]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int nomal_year[15]={0,31,28,31,30,31,30,31,31,30,31,30,31}; class Date
{
private :
int year;
int day;
int mouth;
public :
void fun1();
void fun2(int a,int b,int c);
void display(bool isleap);
bool is_leap();
//protected :
}; void Date::fun1()
{
year = 0;
mouth = 0;
day = 0;
} void Date::fun2(int a,int b,int c)
{
year = a;
mouth = b;
day = c;
} void Date::display(bool isleap)
{
int i,j;
int tot = 0;
if(isleap)
{
for(i = 1; i <= mouth-1; i++)
{
tot += leap_year[i];
} tot += day; printf("%d\n",tot);
}
else
{
for(i = 1; i <= mouth-1; i++)
{
tot += nomal_year[i];
} tot += day; printf("%d\n",tot);
}
} bool Date::is_leap()
{
if(year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
{
return true;
}
else return false;
} int main()
{
int year,mouth,day;
int i,j;
while(scanf("%d%d%d",&year,&mouth,&day) != EOF)
{
if(year == 0 || mouth == 0 || day == 0)break; bool flag = true;
Date D; D.fun1();
D.fun2(year,mouth,day); flag = D.is_leap();
D.display(flag);
}
return 0;
}

PTA第一次作业的更多相关文章

  1. PTA第一次作业和第二次作业

    PTA的第一次作业第一题: #include <stdio.h> int main (void) { int grade,i,N ,a=0,b=0,c=0,d=0,e=0; printf( ...

  2. C 语言学习 第一次作业总结

    第一次的作业是冯老师布置的练习题,需要在pta平台上完成.我这边看不到结果,但是透过冯老师给出的截图,同学们都还是认真的去做的.同时,我这边也布置了一个持续 3 周的作业:熟悉 git 的使用.因为后 ...

  3. java第一次作业0

    lsl321 java第一次作业 #1. 本章学习总结 你对于本章知识的学习总结 本章我们学习了各种java相关文件的使用,以及码云,博客,pat等程序辅助软件,这些对于我们专业的学习有非常大的帮助, ...

  4. C语言的第一次作业总结

    PTA实验作业 题目一:温度转换 本题要求编写程序,计算华氏温度150°F对应的摄氏温度.计算公式:C=5×(F−32)/9,式中:C表示摄氏温度,F表示华氏温度,输出数据要求为整型. 1.实验代码: ...

  5. c语言------第一次作业,分支,顺序结构

    1.1思维导图 1.2本章学习体会及代码量学习体 1.2.1学习体会 初次接触C语言,由于比较懒惰,感觉学习脚步跟不上身边的同学,也比较困扰.但伴随着pta上多次显示的##编译错误##,坚持不懈地问舍 ...

  6. c语言第一次作业1

    第一次作业 一 你对软件工程或者计算机科学与技术专业的了解是什么? 软件工程是一门研究用工程化方法构建和维护有效的,实用的和高质量的软件的学科,涉及程序语言设计,数据库,软件开发工具,系统平台,设计模 ...

  7. pta第一次博客

    目录 pta第一次博客 1.前言 2.设计与分析 第二次作业第二题 第三次作业第一题 第三次作业第二题 第三次作业第三题 3.踩坑心得: 4.改进建议 5.总结 pta第一次博客 1.前言 这三次pt ...

  8. 耿丹CS16-2班第一次作业汇总

    第一次作业统计完成. 注:1.作业顺序:取最早交作业的前3名,依次拿5,2,1分,前提是作业质量较高,否则轮至下一名同学得分,其余同学得0分:2.作业情况:满10分,空一题扣2分,心得写得好的有额外加 ...

  9. 软件工程(QLGY2015)第一次作业小结(含成绩)

    相关博文目录: 第一次作业点评 第二次作业点评 第三次作业点评 Github项目提交 github的代码提交,大部分人都只是提交了单个文件,存在几个问题 请提交完整的项目文件到github 问题:为什 ...

随机推荐

  1. 腾讯在线文档发布:实现QQ、微信多平台多人协作编辑

    18日,腾讯宣布推出专注多人协作的在线文档产品—腾讯文档,据介绍,腾讯文档是一款支持随时随地创建.编辑的多人协作式在线文档工具,拥有一键翻译.实时股票函数和浏览权限安全可控等功能,以及打通QQ.微信等 ...

  2. CentOS6.7上安装Mysql5.7

    CentOS6.7上安装Mysql5.7 2017年07月22日 18:27:05 阅读数:564 环境的配置总是令人作呕,所以这次表明版本条件: 首先,这是一台新机器 其次,CentOS版本如下: ...

  3. isKindOfClass isMemeberOfClass 的区分

    isKindOfClass If you use such constructs in your code, you might think it is alright to modify an ob ...

  4. 软件包管理:yum在线管理-yum命令

    只要我们的电脑可以接入互联网,那么yum源就是配好的,yum命令可以直接使用. 列出的是服务器上全部的rpm包. 包名,包全名的概念只在rpm手动管理时有用. 关键字主要指包名,只要知道了关键字就可以 ...

  5. SQL查询遍历数据方法一 [ 临时表 + While循环]

    以下以SQL Server 2000中的NorthWind数据库中的Customers表为例, 用 临时表 + While循环 的方法, 对Customers表中的CompanyName列进行遍历 c ...

  6. mysql回滚日志

    一.回滚日志(undo log) 1.作用 保存了事务发生之前的数据的一个版本,可以用于回滚,同时可以提供多版本并发控制下的读(MVCC),也即非锁定读 2.内容 逻辑格式的日志,在执行undo的时候 ...

  7. 后台维护常用SQL

    OU.库存组织与子库存 select hou.organization_id ou_org_id, --org_id hou.name ou_name, --ou名称 ood.organization ...

  8. android实操--练习2

    练习2是实现一个计算器的功能:可以加减乘除:可以倒退,可以清空文本. 下面是效果展示: -----------------------布局------------------------------- ...

  9. 并发写Btree原理剖析

    OceanBase 0.4的UpdateServer存储引擎使用了一棵可以多线程并发修改的BTree,读写不冲突,由颜然 开发.线上运行稳定. UpdateServer存储引擎采用类leveldb的方 ...

  10. Python 让PIP源使用国内镜像,提升下载速度和安装成功率

    对于Python开发用户来讲,PIP安装软件包是家常便饭.但国外的源下载速度实在太慢,浪费时间.而且经常出现下载后安装出错问题.所以把PIP安装源替换成国内镜像,可以大幅提升下载速度,还可以提高安装成 ...