C/C++の宿題片付けます 124代目 at TECH
[2ch|▼Menu]
540:デフォルトの名無しさん
09/03/29 22:07:53
>>527 2007年本選の6 有料道路料金
#include<stdio.h>
void swap(int *a, int *b){int c;c=*a;*a=*b;*b=c;}
int get_distance(int from, int to){
static const int distance[]={0, 6, 13, 18, 23, 43, 58};
if(from>to) swap(&from, &to);
return distance[to-1]-distance[from-1];
}
int get_normal_price(int from, int to){
static const int price[][6]={
{ 300}, { 500, 350}, { 600, 450, 250}, { 700, 600, 400, 250},
{1350,1150,1000, 850, 600}, {1650,1500,1350,1300,1150, 500} };
if(from>to) swap(&from, &to);
return price[to-2][from-1];
}
int is_special_time(int hour, int min){
return (1730<=(hour*100+min) && (hour*100+min)<=1930);
}
int get_price(int from_ic, int from_hour, int from_min, int to_ic, int to_hour, int to_min){
int price=get_normal_price(from_ic, to_ic);
if(get_distance(from_ic, to_ic)<=40 && (is_special_time(from_hour, from_min) || is_special_time(to_hour, to_min))) price=((price/2)+50-1)/50*50;
return price;
}
int main(void){
int from_ic=0, from_hour, from_min, to_ic, to_hour, to_min;
for(;;from_ic=0){
scanf("%d %d %d %d %d %d", &from_ic, &from_hour, &from_min, &to_ic, &to_hour, &to_min);
if(from_ic==0) break;
printf("%d\n", get_price(from_ic, from_hour, from_min, to_ic, to_hour, to_min));
}
return 0;
}


次ページ
続きを表示
1を表示
最新レス表示
スレッドの検索
類似スレ一覧
話題のニュース
おまかせリスト
▼オプションを表示
暇つぶし2ch

5410日前に更新/195 KB
担当:undef