5-5

  1. #include <cstdio>
  2. #include <iostream>
  3. #include <cstdlib>
  4. using namespace std;
  5. struct Node
  6. {
  7. int data;
  8. Node *next;
  9. };
  10. int tot = 0;
  11. Node *Node_Creat()
  12. {
  13. Node *head;
  14. head = (Node *)malloc(sizeof(Node));
  15. if(head == NULL)
  16. {
  17. printf("Overflow\n");
  18. exit(1);
  19. }
  20. head = NULL;
  21. Node *p1,*p2;
  22. p1 = (Node *)malloc(sizeof(Node));
  23. if(p1 == NULL)
  24. {
  25. printf("Overflow\n");
  26. exit(1);
  27. }
  28. scanf("%d",&p1 -> data);
  29. while(p1 -> data != -1)
  30. {
  31. if(p1 -> data % 2 == 0)
  32. {
  33. scanf("%d",&p1 -> data);
  34. continue;
  35. }
  36. tot++;
  37. if(head == NULL)
  38. {
  39. head = p1;
  40. }
  41. else
  42. {
  43. p2 -> next = p1;
  44. }
  45. p2 = p1;
  46. p1 = (Node *)malloc(sizeof(Node));
  47. if(p1 == NULL)
  48. {
  49. printf("Overflow\n");
  50. exit(1);
  51. }
  52. scanf("%d",&p1 -> data);
  53. }
  54. p2 -> next = NULL;
  55. return head;
  56. }
  57. void Node_Print(Node *head)
  58. {
  59. Node *p;
  60. p = head;
  61. while(p -> next != NULL)
  62. {
  63. printf("%d ",p -> data);
  64. p = p -> next;
  65. }
  66. printf("%d",p -> data);
  67. }
  68. //没有用到
  69. Node *Node_Delete(Node *head,int num)
  70. {
  71. Node *p1,*p2;
  72. p1 = p2 = head;
  73. if(num == 1)
  74. {
  75. tot--;
  76. head = head -> next;
  77. return head;
  78. }
  79. for(int i = 1; i < num; i++)
  80. {
  81. p2 = p1;
  82. p1 = p1 -> next;
  83. }
  84. p2 -> next = p1 -> next;
  85. tot--;
  86. free(p1);
  87. return head;
  88. }
  89. int main()
  90. {
  91. Node *head;
  92. head = Node_Creat();
  93. Node_Print(head);
  94. return 0;
  95. }

5-4

  1. #include <cstdio>
  2. #include <iostream>
  3. #include <cstdlib>
  4. using namespace std;
  5. struct Node
  6. {
  7. int data;
  8. Node *next;
  9. };
  10. int tot = 0;
  11. Node *Node_Creat()
  12. {
  13. Node *head;
  14. head = (Node *)malloc(sizeof(Node));
  15. if(head == NULL)
  16. {
  17. printf("Overflow\n");
  18. exit(1);
  19. }
  20. head = NULL;
  21. Node *p1,*p2;
  22. p1 = (Node *)malloc(sizeof(Node));
  23. if(p1 == NULL)
  24. {
  25. printf("Overflow\n");
  26. exit(1);
  27. }
  28. scanf("%d",&p1 -> data);
  29. while(p1 -> data != -1)
  30. {
  31. if(p1 -> data % 2 == 1)
  32. {
  33. scanf("%d",&p1 -> data);
  34. continue;
  35. }
  36. tot++;
  37. if(head == NULL)
  38. {
  39. head = p1;
  40. }
  41. else
  42. {
  43. p2 -> next = p1;
  44. }
  45. p2 = p1;
  46. p1 = (Node *)malloc(sizeof(Node));
  47. if(p1 == NULL)
  48. {
  49. printf("Overflow\n");
  50. exit(1);
  51. }
  52. scanf("%d",&p1 -> data);
  53. }
  54. p2 -> next = NULL;
  55. return head;
  56. }
  57. void Node_Print(Node *head)
  58. {
  59. Node *p;
  60. p = head;
  61. if(head == NULL)return ;
  62. while(p -> next != NULL)
  63. {
  64. printf("%d ",p -> data);
  65. p = p -> next;
  66. }
  67. printf("%d\n",p -> data);
  68. }
  69. //还是没有用到
  70. Node *Node_Delete(Node *head,int num)
  71. {
  72. Node *p1,*p2;
  73. p1 = p2 = head;
  74. if(num == 1)
  75. {
  76. tot--;
  77. head = head -> next;
  78. return head;
  79. }
  80. for(int i = 1; i < num; i++)
  81. {
  82. p2 = p1;
  83. p1 = p1 -> next;
  84. }
  85. p2 -> next = p1 -> next;
  86. tot--;
  87. free(p1);
  88. return head;
  89. }
  90. int main()
  91. {
  92. Node *head;
  93. int repeat;
  94. scanf("%d",&repeat);
  95. int i,j;
  96. for(i = 1; i <= repeat; i++)
  97. {
  98. head = Node_Creat();
  99. Node_Print(head);
  100. }
  101. return 0;
  102. }

5-3

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. using namespace std;
  6. int store[1000005];
  7. int s[1000005];
  8. int main()
  9. {
  10. int i,j;
  11. int l,r;
  12. scanf("%d%d",&l,&r);
  13. int tot = l;
  14. for(i = l; i <= r; i++)
  15. {
  16. for(j = 1; j <= sqrt(i); j++)
  17. {
  18. if(i % j == 0)store[i]++;
  19. }
  20. if(sqrt(i) * sqrt(i) == i)
  21. {
  22. store[i] = store[i]*2 - 1;
  23. }
  24. else
  25. {
  26. store[i] *= 2;
  27. }
  28. if(store[i] > store[tot])tot = i;
  29. }
  30. printf("[%d,%d] %d ",l,r,tot);
  31. int cnt = 1;
  32. for(i = 1; i <= tot; i++)
  33. {
  34. if(tot % i == 0)
  35. {
  36. s[cnt] = i;
  37. cnt++;
  38. }
  39. }
  40. printf("%d\n",--cnt);
  41. for(i = 1; i <= cnt; i++)
  42. {
  43. if(i != cnt)
  44. printf("%d ",s[i]);
  45. else
  46. printf("%d",s[i]);
  47. }
  48. return 0;
  49. }

5-2

分文件写法:

student.h

  1. #ifndef STUDENT_H
  2. #define STUDENT_H
  3. #include <iostream>
  4. #include <string>
  5. using namespace std;
  6. class Student
  7. {
  8. private:
  9. int height;
  10. int weight;
  11. public:
  12. string name;
  13. void creat();
  14. void cmp(string cmpname,int h,int w);
  15. void Print();
  16. };
  17. #endif // STUDENT_H

main.cpp

  1. #include "student.h" // class's header file
  2. #include <string>
  3. #include <iostream>
  4. #include <stdlib.h>
  5. #include <algorithm>
  6. #include <cstdio>
  7. using namespace std;
  8. Student stu[1000005];
  9. void Student::creat()
  10. {
  11. if(height > 0)return ;
  12. height = 0;
  13. weight = 0;
  14. }
  15. void Student::cmp(string cmpname,int h,int w)
  16. {
  17. if(h > height)
  18. {
  19. height = h;
  20. weight = w;
  21. name = cmpname;
  22. }
  23. }
  24. void Student::Print()
  25. {
  26. cout << name << " " << height << " "<< weight << endl;
  27. }
  28. int turn[1000005];
  29. int main()
  30. {
  31. int i,j;
  32. int n;
  33. cin >> n;
  34. int a,b,c;
  35. string name;
  36. for(i = 1; i <= n; i++)
  37. {
  38. cin >> a;
  39. turn[i] = a;
  40. stu[a].creat();
  41. cin >> name >> b >> c;
  42. stu[a].cmp(name,b,c);
  43. }
  44. sort(turn+1,turn+n+1);
  45. int cnt = 0;
  46. turn[0] = -1;
  47. for(i = 1; i <= n; i++)
  48. {
  49. if(turn[i] != turn[cnt])
  50. {
  51. cnt = i;
  52. printf("%06d ",turn[i]);
  53. stu[turn[i]].Print();
  54. }
  55. }
  56. return 0;
  57. }
  58. //比较懒,就直接把类中函数定义和主函数放一起了= =

单文件写法:

  1. #include <string>
  2. #include <iostream>
  3. #include <stdlib.h>
  4. #include <algorithm>
  5. #include <cstdio>
  6. using namespace std;
  7. class Student
  8. {
  9. private:
  10. int height;
  11. int weight;
  12. public:
  13. string name;
  14. void creat();
  15. void cmp(string cmpname,int h,int w);
  16. void Print();
  17. };
  18. Student stu[1000005];
  19. void Student::creat()
  20. {
  21. if(height > 0)return ;
  22. height = 0;
  23. weight = 0;
  24. }
  25. void Student::cmp(string cmpname,int h,int w)
  26. {
  27. if(h > height)
  28. {
  29. height = h;
  30. weight = w;
  31. name = cmpname;
  32. }
  33. }
  34. void Student::Print()
  35. {
  36. cout << name << " " << height << " "<< weight << endl;
  37. }
  38. int turn[1000005];
  39. int main()
  40. {
  41. int i,j;
  42. int n;
  43. cin >> n;
  44. int a,b,c;
  45. string name;
  46. for(i = 1; i <= n; i++)
  47. {
  48. cin >> a;
  49. turn[i] = a;
  50. stu[a].creat();
  51. cin >> name >> b >> c;
  52. stu[a].cmp(name,b,c);
  53. }
  54. sort(turn+1,turn+n+1);
  55. int cnt = 0;
  56. turn[0] = -1;
  57. for(i = 1; i <= n; i++)
  58. {
  59. if(turn[i] != turn[cnt])
  60. {
  61. cnt = i;
  62. printf("%06d ",turn[i]);
  63. stu[turn[i]].Print();
  64. }
  65. }
  66. return 0;
  67. }

5-2 纯sort写法

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <stdlib.h>
  5. #include <string>
  6. using namespace std;
  7. class P
  8. {
  9. private:
  10. int height;
  11. int weight;
  12. public:
  13. string name;
  14. int norm;
  15. int display();
  16. void play();
  17. void f(int nor,string nam,int h,int w);
  18. };
  19. void P::play()
  20. {
  21. cout << " " << height << " " << weight << endl;
  22. }
  23. int P::display()
  24. {
  25. int a;
  26. a = height;
  27. return a;
  28. }
  29. void P::f(int nor,string nam,int h,int w)
  30. {
  31. norm = nor;
  32. name = nam;
  33. height = h;
  34. weight = w;
  35. }
  36. P p[105];
  37. bool cmp(P p1,P p2)
  38. {
  39. if(p1.norm != p2.norm)return p1.norm > p2.norm;
  40. else if(p1.display() != p2.display())return p1.display() < p2.display();
  41. }
  42. int main()
  43. {
  44. int n;
  45. string nam;
  46. int i,j;
  47. int w,h;
  48. int nor;
  49. scanf("%d",&n);
  50. for(i = 1; i <= n; i++)
  51. {
  52. cin >> nor >> nam >> h >> w;
  53. p[i].f(nor,nam,h,w);
  54. }
  55. sort(p+1,p+n+1,cmp);
  56. int tot = -1;
  57. for(i = n; i >= 1; i--)
  58. {
  59. if(p[i].norm != tot)
  60. {
  61. tot = p[i].norm;
  62. printf("%06d ",p[i].norm);
  63. cout << p[i].name;
  64. p[i].play();
  65. }
  66. }
  67. return 0;
  68. }

5-1

分文件写法:

main.cpp

  1. #include "date.h"
  2. #include <iostream>
  3. #include <stdlib.h>
  4. #include <cstdio>
  5. using namespace std;
  6. int main()
  7. {
  8. int year,mouth,day;
  9. int i,j;
  10. while(scanf("%d%d%d",&year,&mouth,&day) != EOF)
  11. {
  12. bool flag = true;
  13. Date D;
  14. D.fun1();
  15. D.fun2(year,mouth,day);
  16. flag = D.is_leap();
  17. D.display(flag);
  18. }
  19. return 0;
  20. }

date.h

  1. #ifndef DATE_H
  2. #define DATE_H
  3. #include <iostream>
  4. using namespace std;
  5. class Date
  6. {
  7. private :
  8. int year;
  9. int day;
  10. int mouth;
  11. public :
  12. void fun1();
  13. void fun2(int a,int b,int c);
  14. void display(bool isleap);
  15. bool is_leap();
  16. //protected :
  17. };
  18. #endif // DATE_H

date.cpp

  1. #include "date.h" // class's header file
  2. #include <iostream>
  3. #include <stdlib.h>
  4. #include <cstdio>
  5. using namespace std;
  6. int leap_year[15]={0,31,29,31,30,31,30,31,31,30,31,30,31};
  7. int nomal_year[15]={0,31,28,31,30,31,30,31,31,30,31,30,31};
  8. void Date::fun1()
  9. {
  10. year = 0;
  11. mouth = 0;
  12. day = 0;
  13. }
  14. void Date::fun2(int a,int b,int c)
  15. {
  16. year = a;
  17. mouth = b;
  18. day = c;
  19. }
  20. void Date::display(bool isleap)
  21. {
  22. int i,j;
  23. int tot = 0;
  24. if(isleap)
  25. {
  26. for(i = 1; i <= mouth-1; i++)
  27. {
  28. tot += leap_year[i];
  29. }
  30. tot += day;
  31. printf("%d\n",tot);
  32. }
  33. else
  34. {
  35. for(i = 1; i <= mouth-1; i++)
  36. {
  37. tot += nomal_year[i];
  38. }
  39. tot += day;
  40. printf("%d\n",tot);
  41. }
  42. }
  43. bool Date::is_leap()
  44. {
  45. if(year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
  46. {
  47. return true;
  48. }
  49. else return false;
  50. }

单文件写法:

  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <cstdio>
  4. using namespace std;
  5. int leap_year[15]={0,31,29,31,30,31,30,31,31,30,31,30,31};
  6. int nomal_year[15]={0,31,28,31,30,31,30,31,31,30,31,30,31};
  7. class Date
  8. {
  9. private :
  10. int year;
  11. int day;
  12. int mouth;
  13. public :
  14. void fun1();
  15. void fun2(int a,int b,int c);
  16. void display(bool isleap);
  17. bool is_leap();
  18. //protected :
  19. };
  20. void Date::fun1()
  21. {
  22. year = 0;
  23. mouth = 0;
  24. day = 0;
  25. }
  26. void Date::fun2(int a,int b,int c)
  27. {
  28. year = a;
  29. mouth = b;
  30. day = c;
  31. }
  32. void Date::display(bool isleap)
  33. {
  34. int i,j;
  35. int tot = 0;
  36. if(isleap)
  37. {
  38. for(i = 1; i <= mouth-1; i++)
  39. {
  40. tot += leap_year[i];
  41. }
  42. tot += day;
  43. printf("%d\n",tot);
  44. }
  45. else
  46. {
  47. for(i = 1; i <= mouth-1; i++)
  48. {
  49. tot += nomal_year[i];
  50. }
  51. tot += day;
  52. printf("%d\n",tot);
  53. }
  54. }
  55. bool Date::is_leap()
  56. {
  57. if(year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
  58. {
  59. return true;
  60. }
  61. else return false;
  62. }
  63. int main()
  64. {
  65. int year,mouth,day;
  66. int i,j;
  67. while(scanf("%d%d%d",&year,&mouth,&day) != EOF)
  68. {
  69. if(year == 0 || mouth == 0 || day == 0)break;
  70. bool flag = true;
  71. Date D;
  72. D.fun1();
  73. D.fun2(year,mouth,day);
  74. flag = D.is_leap();
  75. D.display(flag);
  76. }
  77. return 0;
  78. }

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. PHPExcel 基本用法详解

    .header header("Content-Type:application/vnd.ms-excel"); header("Content-Disposition: ...

  2. js 使用jquery.form.js文件上传

    1.文件上传,使用jquery.form.js插件库 <!DOCTYPE html> <html> <head> <meta charset="UT ...

  3. Postman使用js获取日期

    在用postman进行接口自动化测试的时候,某个查询接口需要使用到日期参数进行请求: 假设当前日期为2018-05-07 10:30:20 ,需要传的日期为: beginTime:2018-05-01 ...

  4. C语言头文件、库文件的查找路径

    在 程序设计中,文件包含是很有用的.一个大的程序可以分为多个模块,由多个程序员分别编程.有些公用的符号常量或宏定义等可单独组成一个文件,在其它文件的开头用包含命令包含该文件即可使用.这样,可避免在每个 ...

  5. centos安装samba

    yum -y install samba samba-client samba-swat /etc/init.d/smb start chkconfig --level 35 smb on cp -p ...

  6. jquery ajax基本用法

    <script src="http://libs.baidu.com/jquery/2.1.1/jquery.min.js"></script> <s ...

  7. linux常用命令:ln 命令

    ln是linux中又一个非常重要命令,它的功能是为某一个文件在另外一个位置建立一个同步的链接.当我们需要在不同的目录,用到相同的文件时,我们不需要在每一个需要的目录下都放一个必须相同的文件,我们只要在 ...

  8. 计算概论(A)/基础编程练习1(8题)/3:晶晶赴约会

    #include<stdio.h> int main() { int w; scanf("%d", &w); || w==) { printf("%s ...

  9. 学写网页 #05# CSS Mastery 笔记 1~3

    看到第四章才发现这本书已经太旧了..看到第 3 章为止吧.前三章主要讲的内容:一些编码常识.怎样选择元素.盒子模型(主要是 Margin).定位(绝对.相对.浮动.fixed 等) 第一章 conve ...

  10. php打印负载函数、Linux awk打印负载

    php的sys_getloadavg sys_getloadavt()可以获得系统负载情况.该函数返回一个包含三个元素的数组,每个元素分别代表系统再过去的1.5和15分钟内的平均负载. 与其让服务器因 ...