Discuz! Board

 找回密码
 立即注册
查看: 1105|回复: 1

10.14 结构体

[复制链接]

54

主题

66

帖子

574

积分

高级会员

Rank: 4

积分
574
发表于 2022-10-14 20:07:16 | 显示全部楼层 |阅读模式
  1. #include<bits/stdc++.h>
  2. #include <windows.h>
  3. using namespace std;
  4. struct a
  5. {
  6.         int hou,min,sec,day,yea,mon;
  7. }b;
  8. int t1=0;
  9. int i[2][12]={31,28,31,30,31,30,31,31,30,31,30,31,
  10.               31,29,31,30,31,30,31,31,30,31,30,31};
  11. int rn(int t)
  12. {
  13.     int t1;
  14.     if (t % 4 == 0)
  15.     {
  16.         if (t % 100 == 0)
  17.         {
  18.             if (t % 400 == 0)
  19.                 t1=1;
  20.             else
  21.                 t1=0;
  22.         }
  23.         else
  24.             t1=1;
  25.     }
  26.     else
  27.         t1=0;
  28.     return t1;
  29. }
  30. void CaculateWeekDay(int y,int m, int d)
  31. {
  32.     if(m==1||m==2) {
  33.             m+=12;
  34.             y--;
  35.     }
  36.     int iWeek=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;
  37.     switch(iWeek)
  38.     {
  39.             case 0: printf("星期一"); break;
  40.             case 1: printf("星期二"); break;
  41.             case 2: printf("星期三"); break;
  42.             case 3: printf("星期四"); break;
  43.             case 4: printf("星期五"); break;
  44.             case 5: printf("星期六"); break;
  45.             case 6: printf("星期日"); break;
  46.     }
  47. }
  48. int main(){
  49.     time_t t = time(NULL);
  50.         tm *pt = localtime(&t);
  51.         b.yea = pt->tm_year+1900;
  52.         b.mon = pt->tm_mon+1;
  53.         b.day = pt->tm_mday;
  54.         b.hou = pt->tm_hour;
  55.         b.min = pt->tm_min;
  56.         b.sec = pt->tm_sec;
  57.     rn(b.yea);
  58.     here:
  59.         system("color 0E");
  60.         if(b.sec==60){
  61.                 b.sec=0;
  62.                 b.min+=1;
  63.         }
  64.         if(b.min==60){
  65.                 b.min=0;
  66.                 b.hou+=1;
  67.         }
  68.         if(b.hou==24){
  69.                 b.hou=0;
  70.                 b.day+=1;
  71.         }
  72.         if(b.day==i[rn(b.yea)][b.mon-1]+1){
  73.                     b.day=1;
  74.                     b.mon+=1;
  75.                         }
  76.         if(b.mon==12){
  77.                 b.mon=0;
  78.                 b.yea+=1;
  79.         }
  80.         cout<<setw(4)<<b.yea<<"年  "<<setw(2)<<b.mon<<"月"<<"  "<<setw(2)<<b.day<<"号"<<"  ";
  81.         CaculateWeekDay(b.yea,b.mon,b.day);
  82.         cout<<"  "<<setw(2)<<b.hou<<":"<<setw(2)<<b.min<<":"<<setw(2)<<b.sec<<endl;
  83.         Sleep(1000);
  84.         b.sec+=1;
  85.         system("cls");
  86.         goto here;
  87.     return 0;
  88. }
复制代码
回复

使用道具 举报

54

主题

66

帖子

574

积分

高级会员

Rank: 4

积分
574
 楼主| 发表于 2022-10-14 20:07:44 | 显示全部楼层
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. struct chenji
  4. {
  5.         int math;
  6.         int eng;
  7.         int china;
  8. };
  9. struct stu_1
  10. {
  11.         string name;
  12.         int age;
  13.         float stat;
  14.         chenji t;
  15. }s[3];
  16. bool cmp(stu_1 a,stu_1 b)
  17. {
  18.         return a.stat>b.stat;
  19. }
  20. int main()
  21. {
  22.         s[0].name="张1";
  23.         s[1].name="张2";
  24.         s[2].name="朱";
  25.         s[0].age=12;
  26.         s[1].age=12;
  27.         s[2].age=120;
  28.         s[0].stat=1000;
  29.         s[1].stat=10;
  30.         s[2].stat=8000000000;
  31.         s[0].t.china=100;
  32.         s[1].t.china=100;
  33.         s[2].t.china=1000;
  34.         s[0].t.eng=100;
  35.         s[1].t.eng=100;
  36.         s[2].t.eng=1000;
  37.         s[0].t.math=100;
  38.         s[1].t.math=100;
  39.         s[2].t.math=1000;
  40.         sort(s,s+3,cmp);
  41.         for(int i=0;i<=2;i++){
  42.                 cout<<s[i].name<<" ";
  43.         }
  44.         return 0;
  45. }
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|DiscuzX

GMT+8, 2025-2-13 15:14 , Processed in 0.051993 second(s), 26 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.. 技术支持 by 巅峰设计

快速回复 返回顶部 返回列表