标签:
1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 struct route_record { 5 int card_num; 6 char card_kind; 7 int balance; 8 9 char begin_station[2]; 10 char end_station[2]; 11 12 int begin_time_hour; 13 int begin_time_minute; 14 15 int end_time_hour; 16 int end_time_minute; 17 18 }; 19 //小写转大写 20 void lowToUp(char *ch){ 21 if(*ch >= ‘a‘ && *ch <= ‘z‘) 22 *ch = *ch - (‘a‘ - ‘A‘); 23 } 24 //将时间字符串转为int型时间 25 void timeStringToInt(char *pTime, int *hour, int *minute){ 26 27 *hour = (*pTime - ‘0‘) * 10 + (*(pTime+1) - ‘0‘); 28 *minute = (*(pTime + 1) - ‘0‘) * 10 + (*(pTime+2) - ‘0‘); 29 30 } 31 32 //判断是否是有效路径 33 int isValidRoute(char *pRoute){ 34 char s_label = *pRoute; 35 char num_label = *(pRoute+1); 36 37 if( ( s_label == ‘S‘ || s_label == ‘s‘) && ( num_label - ‘0‘ >= 1 && num_label - ‘0‘ <= 6) ) 38 return 1; 39 else 40 return 0; 41 } 42 //判断是否进站时间大于出站时间(有效时间) 43 //0------无效 44 //1------有效 45 46 int isValidTime(int beginHour, int beginMinute, int endHour, int endMinute){ 47 if(endHour > beginHour || (endHour == beginHour && endMinute > beginMinute)) 48 return 1; 49 else 50 return 0; 51 } 52 //判断是否是同一站点 53 int isSameStation(char *pRouteBeg, char *pRouteEnd){ 54 if( 0 == strcmp(pRouteBeg, pRouteEnd) ){ 55 return 1; 56 } 57 else 58 return 0; 59 } 60 //判断是否是特殊时间段 61 //返回值: 62 // 0-------不是特殊时间段 63 // 1-------特殊时间段一 64 // 2-------特殊时间段二 65 66 int isSpecialTime(int beginHour, int beginMinute) { 67 if(beginHour >= 7 && beginHour < 9) 68 return 1; 69 if( ( beginHour == 16 && beginMinute >= 30 ) || ( beginHour == 18 && beginMinute < 30 ) || beginHour == 17) 70 return 1; 71 72 if(beginHour >10 && beginHour < 11 || (beginHour >= 15 && beginHour < 16)) 73 return 2; 74 75 return 0; 76 } 77 78 void initialise(){} 79 void queueRecords(){} 80 void cancelCard(){} 81 82 83 //打折系数 84 double discount(int time_label, char card_label){ 85 if(time_label == 0 || time_label == 1 && card_label == ‘C‘)//普通时段 特殊时段一 普通卡 86 return 1.0; 87 if(time_label == 2 && card_label == ‘C‘) //特殊时段二 普通卡 88 return 0.5; 89 90 if(time_label == 0 && card_label == ‘B‘) //普通时段 老年卡 91 return 0.9; 92 if(time_label == 1 && card_label == ‘B‘) //特殊时段一 老年卡 93 return 1.0; 94 if(time_label == 2 && card_label == ‘B‘) //特殊时段二 老年卡 95 return 0.5; 96 } 97 98 //请求扣费 99 void requestCharge(char *infor){ 100 int card_num = 0; 101 char card_kind = 0; 102 int balance; char balance_char[4] = {0}; 103 104 char begin_station[3] = {0}; 105 char end_station[3] = {0}; 106 107 int begin_time_hour = 0; 108 int begin_time_minute = 0; 109 110 int end_time_hour = 0; 111 int end_time_minute = 0; 112 113 int pBlackPos[6] = {0}; 114 int i = 0; 115 int j = 0; 116 while(‘\0‘ != *(infor+i) ){ 117 if(*(infor+i) == ‘ ‘) 118 pBlackPos[j++] = i; 119 i++; 120 } 121 122 card_num = *infor - ‘0‘; 123 card_kind = *(infor+2); 124 lowToUp(&card_kind); 125 126 strncpy(balance_char, infor+pBlackPos[1]+1, pBlackPos[2]-pBlackPos[1]-1); 127 balance = atoi(balance_char); 128 129 timeStringToInt(infor+pBlackPos[2]+1, &begin_time_hour, &begin_time_minute); 130 timeStringToInt(infor+pBlackPos[4]+1, &end_time_hour, &end_time_minute); 131 132 strncpy(begin_station, infor+pBlackPos[3]+1,2); 133 strncpy(end_station, infor+pBlackPos[5]+1,2); 134 lowToUp(begin_station); 135 lowToUp(end_station); 136 137 138 //两个站点之间的距离 139 140 //计算车费 141 142 } 143 //对输入的参数进行分类 144 // r/R------程序初始化 145 // c/C------请求扣费 146 // h/H------查询票卡消费历史记录 147 // d/D------注销票卡 148 149 void getInputOrder(char *pOrderString){ 150 151 char order_label = *pOrderString;// 152 switch (order_label){ 153 case ‘r‘: 154 case ‘R‘: 155 initialise(); 156 break; 157 case ‘c‘: 158 case ‘C‘: 159 requestCharge(pOrderString+2); 160 break; 161 case ‘h‘: 162 case ‘H‘: 163 queueRecords(); 164 break; 165 case ‘d‘: 166 case ‘D‘: 167 cancelCard(); 168 break; 169 default: 170 break; 171 } 172 173 } 174 175 int main() 176 { 177 char routeBeg[3] = "S3"; 178 char routeEnd[3] = "S3"; 179 char info[] = "C 9 C 20 12:05 S1 11:20 S4"; 180 181 getInputOrder(info); 182 printf("%d\n", isSameStation(routeBeg, routeEnd)); 183 //printf("%d\n", isValidRoute(route)); 184 return 0; 185 }
标签:
原文地址:http://www.cnblogs.com/wanghui390/p/4376610.html