博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PTA第二次作业
阅读量:6689 次
发布时间:2019-06-25

本文共 8046 字,大约阅读时间需要 26 分钟。

#include 
#include
#include
using namespace std;class myDate{ private: int year; int mouth; int day; public: myDate(int y,int m,int d):year(y),mouth(m),day(d){}; void display();};class myTime{ private: int hour; int mini; public: myTime(int h,int min):hour(h),mini(min){}; void display();};void myDate::display(){ printf("%04d/%02d/%02d ",year,mouth,day);}void myTime::display(){ printf("%02d:%02d\n",hour,mini);}int main(){ int y,m,d,h,min; int i,j; while(scanf("%d%d%d%d%d",&y,&m,&d,&h,&min) != EOF) { if(y == 0)break; myDate Date(y,m,d); myTime Time(h,min); Date.display(); Time.display(); } return 0;}

#include 
#include
#include
#include
using namespace std;class calculate{ public: int s[105]; calculate() { memset(s,0,sizeof(s)); } void found();};void calculate::found(){ int l,r; int i,j; l = r = 1; int tot = 0; int cnt = 0; for(i = 1; i <= 7; i++)//i左 { cnt = 0; for(j = i; j <= 7; j++)//j右 { cnt += s[j]; if(cnt > tot) { tot = cnt; l = i; r = j; } else if(cnt == tot) { if(r - l <= j - i && tot == cnt) //相等的时候 取区间范围比较小的 continue; tot = cnt; l = i; r = j; } } } if(tot <= 0) printf("won't buy!\n"); else printf("%d %d %d\n",tot,l,r);}int main(){ int i,j; while(1) { calculate cal; scanf("%d%d%d%d%d%d%d",&cal.s[1],&cal.s[2],&cal.s[3], &cal.s[4],&cal.s[5],&cal.s[6],&cal.s[7]); if(cal.s[1] == 0 && cal.s[2] == 0 && cal.s[3] == 0 && cal.s[4] == 0 && cal.s[5] == 0 && cal.s[6] == 0 && cal.s[7] == 0)break; cal.found(); } return 0;}//-1 -1 1 -1 1 -1 1

继承

#include 
#include
#include
#include
using namespace std;class Group{ protected: string name;//姓名 public: virtual void display()=0;//显示考核成绩};//====class Group_A : public Group{ public: int getscore; void display(); Group_A(string s,int score):getscore(score){name = s;};};void Group_A::display(){ cout << name << " " << 'A' << " " << getscore << endl;}//====class Group_B : public Group{ public: int getscore; void display(); Group_B(string s,int score):getscore(score){name = s;};};void Group_B::display(){ cout << name << " " << 'B' << " " << getscore << endl;}//====int cal_Ascore(string s,int len){ int i,j; int win = 0; int lose = 0; int tot = 0; string play; stringstream stream; for(i = 3 + len; i < s.length(); i++) { if(s[i] == ' ') { if(play != "") { stream << play; stream >> win; stream.clear(); play = ""; } continue; } play += s[i]; } if(play != "") { stream << play; stream >> lose; stream.clear(); } tot = 2 * win - lose; return tot;}int cal_Bscore(string s,int len){ int tot = 0; int pre = 0; int beh = 0; int i,j; string play; stringstream stream; for(i = 3 + len; i < s.length(); i++) { if(s[i] == ':') { stream << play; stream >> pre; stream.clear(); play = ""; continue; } else if(s[i] == ' ') { stream << play; stream >> beh; stream.clear(); if(pre > beh) { tot += pre - beh; } else if(pre < beh) { tot -= beh - pre; } pre = 0; beh = 0; play = ""; continue; } else { play += s[i]; } } if(play != "") { stream << play; stream >> beh; stream.clear(); if(pre > beh) { tot += pre - beh; } else if(pre < beh) { tot -= beh - pre; } } return tot;}//====int main(){ Group *pg[20]; int cnt = 1; int A_win; int A_lose; int i,j; while(1) { string Gsta; getline(cin,Gsta); if(Gsta[0] == '0')break; string name; int namelen = 0; int score = 0; for(i = 2; i < Gsta.length(); i++) { if(Gsta[i] == ' ')break; name += Gsta[i]; namelen ++; } if(Gsta[0] == 'A') { score = cal_Ascore(Gsta,namelen); pg[cnt++] = new Group_A(name,score); //Group_A A1(name,score); //A1.display(); } else if(Gsta[0] == 'B') { score = cal_Bscore(Gsta,namelen); pg[cnt++] = new Group_B(name,score); //Group_B B1(name,score); //B1.display(); } } for(i = 1; i < cnt; i++) { pg[i] -> display(); } return 0;}

说好的顺序表写成了链表orz。

#include 
#include
#include
#include
#define LEN sizeof(SeqList)using namespace std;struct SeqList{ int data; SeqList* next;};typedef SeqList* point;point List_Creat(int tot){ point head; point p1,p2; head = (point)malloc(LEN); if(head == NULL) { printf("Overflow\n"); exit(1); } head = NULL; p1 = (point)malloc(LEN); if(p1 == NULL) { printf("Overflow\n"); exit(1); } scanf("%d",&p1 -> data); if(tot == 1) { head = p1; head -> next = NULL; return head; } for(int i = 1; i < tot; i++) { if(head == NULL) { head = p1; } else { p2 -> next = p1; } p2 = p1; p1 = (point)malloc(LEN); if(p1 == NULL) { printf("Overflow\n"); exit(1); } scanf("%d",&p1 -> data); } p2 -> next = p1; p1 -> next = NULL; return head;}point Print(point head){ point p; p = head; printf("%d",p -> data); p = p -> next; while(p != NULL) { printf(" %d",p -> data); p = p -> next; } printf("\n");}point Insert(point head,int num){ point p,p1,p2; p = (point)malloc(LEN); if(p == NULL) { printf("Overflow\n"); exit(1); } p -> data = num; p -> next = NULL; p1 = p2 = head; if(head -> data >= num) { p -> next = head; head = p; return head; } else { while(p1 -> next != NULL) { if(p1 -> data >= num) { break; } else { p2 = p1; p1 = p1 -> next; } } if(p1 -> next == NULL && p1 -> data < num) { p1 -> next = p; p -> next = NULL; } else { p2 -> next = p; p -> next = p1; } } return head;} int main(){ int t; int i,j; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); point head; head = List_Creat(n); int i_data; scanf("%d",&i_data); head = Insert(head,i_data); printf("size=%d:",n + 1); Print(head); } return 0;}

转载地址:http://tokoo.baihongyu.com/

你可能感兴趣的文章
格式化磁盘
查看>>
Linux 下内网流量控制工具
查看>>
KVM基本功能管理与使用
查看>>
胖AP与瘦AP的区别以及胖瘦AP组网的优劣对比
查看>>
复习sed的相关内容
查看>>
NetScaler OTP双因子身份认证登录演示
查看>>
centos系统目录结构
查看>>
python Class:面向对象高级编程 __getattr__
查看>>
思科dhcp配置思路
查看>>
“中国制造2025”+云计算,制造业转型的新可能
查看>>
JavaScript基础(一)
查看>>
python爬取QQ说说并生成词云图,回忆满满
查看>>
psutil
查看>>
如何过滤出已知当前目录下oldboy中的所有一级目录
查看>>
判断语句介绍
查看>>
2019智能家居展览会-资讯智能家居博览会
查看>>
阿里的Spring框架面试题到底有多难?这五大问题你又掌握了多少!
查看>>
搭建简单的云waf
查看>>
LVM逻辑卷小结
查看>>
浅淡个人学习嵌入式Linux过程
查看>>