TJU 2460 Ticket Discount (Asia - Beijing 2003)

TJU 2460 Ticket Discount (Asia - Beijing 2003)

WA 了很多次...有几个小细节需要处理就是读入数据 控制精度 判断闰年 还有最重要的是理解清楚题意。。。

 

  1 #include < stdio.h >
  2 #define  SIZE 400
  3
  4 int  flag , flag2;
  5 char  s1[SIZE],s5[SIZE],s3[SIZE];
  6 int  s4,s2,s6;
  7 char  month[ 12 ][ 5 ] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"} ;
  8 int  dat[ 12 ] = {31,28,31,30,31,30,31,31,30,31,30,31} ;
  9   int  date;
 10 struct  Q {
 11       int qn;
 12       int qy;
 13       int qr;
 14       
 15       int en;
 16       int ey;
 17       int er;
 18       
 19       int way;
 20       int num;
 21}
;
 22  Q a;
 23 int  shu() {
 24    int nn = 0;
 25    while(1){
 26            if(  a.qn == a.en && a.er ==a.qr && a.ey == a.qy) break;
 27             if(nn>31break;
 28             if(flag == 1) dat[1= 29;
 29             else
 30             dat[1= 28;
 31            
 32           a.qr++;
 33           if(a.qr>dat[a.qy-1])
 34           {
 35            a.qr = a.qr - dat[a.qy-1];
 36            a.qy++;
 37            if(a.qy>12){
 38            a.qy = a.qy -12;
 39            a.qn++;
 40             if(flag2 ==1 ){
 41             flag = 1;
 42             }

 43            }

 44           }

 45           nn++;
 46    }

 47    return nn ;
 48}

 49
 50 int  main() {
 51    int key ;
 52    int i ;
 53    while(1){
 54             key = 0 ;        
 55             int num =0;
 56            
 57             scanf("%s %d %s %d %s ",s1,&s2,s3,&s4,s5);
 58             if(s5[0== 'a'){
 59                      while(1){
 60                               char temp;
 61                               scanf("%c",&temp);
 62                               if(temp == '<')
 63                               num++;
 64                               if(temp == '>')
 65                               num--
 66                               if(num == 0break;                            
 67                      }

 68             }

 69             scanf("%d",&s6);
 70             //printf("%s %d %s %d %s %d\n",s1,s2,s3,s4,s5,s6);
 71              if(s6 == 0break;
 72             a.en = s4;
 73             a.qn = s2;
 74             a.num = s6;
 75             for(i = 0 ; i <12 ;i++ )
 76             if(s1[0== month[i][0&& s1[1== month[i][1&& s1[2==month[i][2] ){
 77             a.qy = i+1;              
 78             break;
 79             }

 80             a.qr = 10*(s1[4]-'0')+(s1[5]-'0');
 81              for(i = 0 ; i <12 ;i++ )
 82             if(s3[0== month[i][0&& s3[1== month[i][1&& s3[2==month[i][2] ){
 83             a.ey = i+1;              
 84             break;
 85             }

 86             a.er = 10*(s3[4]-'0')+(s3[5]-'0');
 87             
 88               int m = 100 ;
 89               
 90             switch(s5[0]){
 91             case 'p':a.way = 1 ;m = 90*m; break;
 92             case 'o':a.way = 2 ;m = 85*m; break;
 93             case 'a':a.way = 3 ;m = 80*m; break;
 94             }

 95             if(a.num>=20){
 96                           m = 80*m;
 97             }

 98             else
 99             if(a.num>=5 && a.num<=19){
100                          m = 90*m;
101             }

102             else
103             m = m*100;
104             
105             date = 0;
106             flag = 0;
107             if(a.qn%400 == 0){
108             flag = 1;
109             }

110             else{
111              if(a.qn%4 == 0 && a.qn%100!=0){
112              flag = 1;
113              }

114             }

115             flag2 = 0;
116              if(a.en%400 == 0){
117             flag2 = 1;
118             }

119             else{
120              if(a.en%4 == 0 && a.en%100!=0){
121              flag2 = 1;
122              }

123             }

124            date = shu();           
125             if(date>=30) m = m*60;
126             else
127             if(date>=15) m = m*70;
128             else
129             if(date>=7) m = m*90;
130            else
131            m = m*100;
132            
133            char ss[SIZE];          
134            
135             sprintf(ss,"%d\n",m);
136             
137             printf("%c%c",ss[0],ss[1]);
138             if(ss[2]=='0'&&ss[3== '0'{printf("\n");continue;}
139             else
140             printf(".");
141             
142             printf("%c",ss[2]);
143             if(ss[3]=='0'){printf("\n");continue;}
144             else
145             {
146                 printf("%c\n",ss[3]);
147             }

148             
149    }

150
151return 0 ;
152}

153
154

 

 

你可能感兴趣的:(TJU 2460 Ticket Discount (Asia - Beijing 2003))