fzu_oop_east 第一次作业
2016-05-24 20:58
302 查看
第一题
题目:
代码:
第二题
题目:
代码
第三题
题目:
代码
第四题
题目:
代码
第五题(与第四题相同,就不贴代码了)
题目:
这一系列下来的收获:
题目:
代码:
#include<iostream> #include<cstdio> using namespace std; class Date { public: int year; int month; int day; int calculation(int judge,int month,int day); }; int Date::calculation(int judge,int month,int day) { int result=0; result=(month-1)*31+day; if(month>2) { if(judge==1) //如果是闰年 { result=result-(month/2)-2; } else { result=result-(month/2)-1; } } return result; } int main() { Date date1; int year1,month1,day1,decide,number; while(scanf("%d %d %d",&year1,&month1,&day1)!=EOF) { decide=0; if(year1==0 && month1==0 && day1==0) { break; } else { if(year1%4==0&&year1%100!=0||year1%400==0) { decide=1; } number=date1.calculation(decide,month1,day1); cout<<number<<endl; } } return 0; }
第二题
题目:
代码
#include<iostream> #include<cstring> #include <string> #include<cstdio> #include<algorithm> using namespace std; class Students { private: int room; string name; int height; int weight; public: void begin() { height = 0; } void getin(string a,int b,int c,int d) { if(b>height) { room=d; name=a; height=b; weight=c; } } void print() { printf("%06d ",room); cout<<name<<" "<<height<<" "<<weight<<endl; } int ad() { if(height!=0) return 0; else return 1; } }student[1000000]; int a[1000000]; int main() { int n,i,j=0; cin>>n; for(i=0;i<n;i++) { int room,height,weight; string name; cin>>room>>name>>height>>weight; a[j]=room; j=j+student[room].ad(); student[room].getin(name,height,weight,room); } sort(a,a+j); for(i=0;i<j;i++) { student[a[i]].print(); } return 0; }
第三题
题目:
代码
#include<iostream> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; int num[100000][1000]; int main() { int begin,end,i,n,m,x,y,how=0,how1=0,result=0; cin>>begin>>end; for(n=begin;n<=end;n++) { how=0; m=sqrt(n); for(i=1;i<=m;i++) { x=n%i; if(x==0) { y=n/i; num [how]=i; how++; if(i!=y) { num [how]=y; how++; } } } if(how>how1) { how1=how; result=n; } } sort(num[result],num[result]+how1); cout<<"["<<begin<<","<<end<<"] "; cout<<result<<" "<<how1<<endl; for(i=0;i<how1-1;i++) { cout<<num[result][i]<<" "; } cout<<num[result][i]; return 0; }
第四题
题目:
代码
#include<iostream> #include<cstdio> #include<stdlib.h> using namespace std; struct Node { int data; struct Node *next; }; int main() { Node *change(Node *head); int repeat; cin>>repeat; for(int i=0;i<repeat;i++) { int n; Node *head,*p1,*p2; head=NULL; p2=(Node*)malloc(sizeof(Node)); while(scanf("%d",&n)!=EOF) { p1=(Node*)malloc(sizeof(Node)); if(n==-1) { p2->next=NULL; break; } else { p1->data=n; if(head == NULL) /*如果是开头的话*/ { head=p1; } else { p2->next=p1; } p2=p1; } } /*到这里没问题*/ head=change(head); /*删去奇数的节点*/ if(head != NULL) /*输出*/ { while(head->next != NULL) { cout<<head->data<<" "; head=head->next; } cout<<head->data<<endl; } } return 0; } Node *change(Node *head) { Node *p1,*p2; while(head!=NULL && head->data%2 != 0) { head=head->next; } p1=p2=head; if(head==NULL) return head; p1=p1->next; while(p1 != NULL) { if(p1->data%2 != 0) { while(p1!=NULL && p1->data%2 != 0) { p1=p1->next; } p2->next=p1; } else { p2=p1; p1=p1->next; } } return head; }
第五题(与第四题相同,就不贴代码了)
题目:
这一系列下来的收获:
相关文章推荐
- Rails部署云环境配置(Passenger+Apache)
- Linux内核态与用户态通信的常用方法
- Centos: Python CGI Script environment deployment
- ubuntu14.04 tomcat7安装,环境变量配置
- linux crontab 学习
- Linux内核设计与实现读书笔记(8)-内核同步方法【转】
- Linux中bond网卡绑定方法
- openssl生成自签名证书
- keepalived 高可用配置实例
- GIT - 版本控制工具
- [bash] how to use bash-shell array
- linux下的中文乱码
- 套接字的多种可选项(Linux + GCC)
- 完整配置hadoop的环境变量
- 给飞驰的法拉利换引擎 - 谈边做业务边做架构重构(2)—— 合纵连横
- Hadoop生态系统
- 支付宝系统架构
- centos 6.5 实现Mysql 数据库读写分离
- 执行sh ./xxx.sh出现:“Syntax error: “(” unexpected”的解决方法
- 树莓派 常用软件及配置(opencv安装,中文环境设置,VNC配置,截屏)