145 - Gondwanaland Telecom

All about problems in Volume 1. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

taj79
Learning poster
Posts: 74
Joined: Sun Jun 09, 2002 11:56 am
Location: India
Contact:

145 WA

Post by taj79 »

Why am i getting wrong answer???

Code: Select all


#include<stdio.h>
#include<stdlib.h>

int which_time_group( int a );
float func(char ch,int *u1,int *u2,int *u3,float R[][3],int lt[],int ut[],int a,int b,int c,int d);
main()
{int a,b,c,d,ph1,ph2,lt[3],ut[3];
 int u1,u2,u3,i=0;
 float amnt;
 char ch;
 float R[5][3];

 R[1][1] = 0.10;R[1][2] = 0.06;R[1][3] = 0.02;
 R[2][1] = 0.25;R[2][2] = 0.15;R[2][3] = 0.05;
 R[3][1] = 0.53;R[3][2] = 0.33;R[3][3] = 0.13;
 R[4][1] = 0.87;R[4][2] = 0.47;R[4][3] = 0.17;
 R[5][1] = 1.44;R[5][2] = 0.80;R[5][3] = 0.30;

 lt[1] = 8*60;ut[1] = 18*60;
 lt[2] = ut[1];ut[2] = 22*60;
 lt[3] = ut[2];ut[3] = lt[1];

 do{
    do{
        scanf("%c",&ch);
      }while( !(ch >= 41 && ch <= 69) && !(ch == '#') );

  if(ch == '#')
    { printf("\n");
      exit(1);
    }
   scanf("%d%d",&ph1,&ph2);
   ph2 *= -1;
   scanf("%d%d%d%d",&a,&b,&c,&d);
   u1=0;u2=0;u3=0;/* This keeps the time in different time category  */
   amnt = func(ch,&u1,&u2,&u3,R,lt,ut,a,b,c,d);
   printf("\n%5d-",ph1);
   if(ph2/1000 > 0)
   printf("%4d",ph2);
   else{
       if(ph2/100 > 0)
	printf("0%3d",ph2);
       else if(ph2/10 > 0)
	  printf("00%2d",ph2);
	   else if(ph2 > 0)
	  printf("000%d",ph2);
	    else
	     printf("0000");
       }
   printf("%6d%6d%6d%3d%8.2f",u1,u2,u3,ch,amnt);
   }while(ch != '#');

}

int which_time_group( int a )
{
  if( a>= 8 && a < 18)
   return(1);
   if(a >= 18 && a< 22)
    return(2);
   else
     return(3);
}

float func(char ch,int *u1,int *u2,int *u3,float R[][3],int lt[],int ut[],int a,int b,int c,int d)
{int g1,g2,z1,z2,t,t1,t2,t3;
 int dist_group;

 float amnt;
  g1 = which_time_group(a);
  g2 = which_time_group(c);

  *u1=0;
  *u2=0;
  *u3=0;
  /* printf("\n Inside func() \n"); */

  if(ch == 'A')
   dist_group = 1;
  if(ch == 'B')
   dist_group = 2;
  if(ch == 'C')
   dist_group = 3;
  if(ch == 'D')
   dist_group = 4;
  if(ch == 'E')
   dist_group = 5;


     z1 = 100*a + b;
     z2 = 100*c + d;

     if(z1 <  z2)/* Midnight doesn't come inbetween */
     { /* printf("\nInside func() Midnight doesn't come in between \n ");
       printf("\n g1 = %d g2 = %d",g1,g2);  */
       if(g1 == g2)
       { /* printf("\n g1 = %d g2 = %d",g1,g2);  */

	  if(z2 >= 2200 && z1 <= 800)
	 { t3 = 8*60 - (60*a + b)+ 60*c + d - 22*60;
	   t1 = 10*60;
	   t2 = 4*60;
	   *u1 = t1;
	   *u2 = t2;
	   *u3 = t3;
            return( t3*R[dist_group][3] + t1*R[dist_group][1] +  t2*R[dist_group][2]);
	 }
         t = 60*c + d -(60*a + b);
	 if(g1 == 1)
	   *u1 = t;
	if(g1 == 2)
	  *u2 = t;
	if(g1 == 3)
	  *u3 = t;
	 return( t*R[dist_group][g1] );
       }
       if(g2 - g1 == 1)
       {/*  printf("\n g1 = %d g2 = %d",g1,g2);  */
        t1 = ut[g1] - (60*a + b);
	t2 = 60*c + d - lt[g2];
	if(g1 == 1)
	 { *u1 = t1;
           *u2 = t2;
	 }
	 if( g1 == 2)
	 { *u2 = t1;
	   *u3 = t2;
	 }
	 return( t1*R[dist_group][g1]  + t2*R[dist_group][g2] );
       }
       if(g1 == 3 && g2 == 1)
       {
        t3 = 8*60 - (60*a + b);
	t1 = 60*c + d - 8*60;
	*u3 = t3;
	*u1 = t1;
	return( t3*R[dist_group][g1]  + t1*R[dist_group][g2] );
	}
       if(g2 - g1 == 2)
       { /* printf("\n g1 = %d g2 = %d",g1,g2);*/
	t1 = ut[g1] - (60*a + b);
	t3 = 60*c + d - lt[g2];
	*u1 = t1;
	*u2 = 4*60;
	*u3 = t3;
	return( t1*R[dist_group][g1]  + 4*60*R[dist_group][g1 +1] + t3*R[dist_group][g2] );
        }
	if(g1 == 3 && g2 == 2)
	{
	 t3 = 8*60 - (60*a + b);
	 t1 = 10*60;
	 t2 = 60*c + d - 18*60;
	 *u1 = t1;
	 *u2 = t2;
         *u3 = t3;
	 return( t3*R[dist_group][3] + t1*R[dist_group][1] +  t2*R[dist_group][2]);
	}

      }
     else/* Midnight does come in between */
     {/* printf("\nInside func() Midnight does come in between \n ");  */
      amnt = 0;
       if(g1 == 3)
       {
	if(g2 == 3)
	 {/* printf("\n g1 = %d g2 = %d",g1,g2);  */
	  if(z1>= 2200)/* if time starts before midnight  */
	   { if(z2 >= 2200)
	     {*u3 = 24*60 - 60*a-b + 8*60 + 60*c + d - 22*60;
	      *u1 = 10*60;
	      *u2 =  4*60;
	     }
	     else{
	          *u3 = 24*60 - 60*a-b + 60*c + d;

		 }
	    }
	  else {/* if time starts after midnight  */

		  *u3 = 8*60 - 60*a-b + 60*c + d + 2*60;
		  *u1 = 10*60;
	          *u2 =  4*60;
		}

	  amnt = R[dist_group][3]*(*u3) + R[dist_group][1]*(*u1) +
			R[dist_group][2]*(*u2);
	  }/* END of g2 == 3  */
        else if(g2 == 1)
	     {/*  printf("\n g1 = %d g2 = %d",g1,g2);  */
	       *u3 = 24*60 - 60*a-b + 8*60;
	       *u1 = 60*c + d - 60*8;
               amnt = R[dist_group][g1]*(*u3) + R[dist_group][g2]*(*u1);
	     }
	 else /* g2 == 2 */
	      {/*  printf("\n g1 = %d g2 = %d",g1,g2);  */
	        *u3 = 24*60 - 60*a-b + 8*60;
		*u1 = 10*60;
		*u2 = 60*c + d - 18*60;
	        amnt = R[dist_group][3]*(*u3) + R[dist_group][1]*(*u1) +
					R[dist_group][2]*(*u2);
	      }


	return(amnt);
	}

      if(g1 == 2)
      {
	if(g2 == 3)
	  {/* printf("\n g1 = %d g2 = %d",g1,g2); */
	    *u2 = 22*60 - 60*a-b;
	    *u3 = 2*60 + 60*c + d;
	    amnt = R[dist_group][2]*(*u2) + R[dist_group][3]*(*u3) ;
	  }
	else if(g2 == 1)
	  {/* printf("\n g1 = %d g2 = %d",g1,g2); */
	    *u2 = 22*60 - 60*a-b;
            *u3 = 10*60;
	    *u1 = 60*c + d - 8*60;
	    amnt = R[dist_group][3]*(*u3) + R[dist_group][1]*(*u1) +
	               R[dist_group][2]*(*u2);
	  }
	  else
           {/* printf("\n g1 = %d g2 = %d",g1,g2); */
	     *u3 = 10*60;
	     *u1 = 10*60;
	     *u2 = 60*c + d -18*60 + 22*60 - 60*a-b;
	     amnt = R[dist_group][3]*(*u3) + R[dist_group][1]*(*u1) +
			R[dist_group][2]*(*u2);
	   }

        return(amnt);
      }

      if(g1 == 1)
      {
	if(g2 == 3)
	 { /* printf("\n g1 = %d g2 = %d",g1,g2); */
	   *u1 = 18*60 - 60*a-b;
	   *u2 = 4*60;
	   *u3 = 2*60 + 60*c + d;
	   amnt = R[dist_group][3]*(*u3) + R[dist_group][1]*(*u1) +
			R[dist_group][2]*(*u2);
	 }
	 else
	  { /* printf("\n g1 = %d g2 = %d",g1,g2); */
	    *u2 = 4*60;
	    *u3 = 10*60;
	    *u1 = 18*60 - 60*a - b + 60*c+d - 8*60;
	    amnt = R[dist_group][3]*(*u3) + R[dist_group][1]*(*u1) +
			R[dist_group][2]*(*u2);
	  }

	return(amnt);
      }
   }

 }



titid_gede
Experienced poster
Posts: 187
Joined: Wed Dec 11, 2002 2:03 pm
Location: Mount Papandayan, Garut

145 Gondwanaland Telecom

Post by titid_gede »

always got WA. do you have any special inputs?
Kalo mau kaya, buat apa sekolah?
ttwu
New poster
Posts: 8
Joined: Tue May 13, 2003 4:31 pm

Post by ttwu »

Maybe you've forgotten a call that lasts for exactly 24hr?
titid_gede
Experienced poster
Posts: 187
Joined: Wed Dec 11, 2002 2:03 pm
Location: Mount Papandayan, Garut

Post by titid_gede »

well, how is the input if call last for 24 hours? what is the difference between call last for 14 hours and call last below 1 minute?
Kalo mau kaya, buat apa sekolah?
deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm

Post by deddy one »

the input could looked like this

Code: Select all

A 123-1234 11 12 11 12
can you handle that input ??
titid_gede
Experienced poster
Posts: 187
Joined: Wed Dec 11, 2002 2:03 pm
Location: Mount Papandayan, Garut

Post by titid_gede »

hmm i thought that means call < 1 minute.
anyway still got WA. here is my code :
[c]
---- cut ----
[/c]
Last edited by titid_gede on Sat May 17, 2003 9:30 am, edited 1 time in total.
Kalo mau kaya, buat apa sekolah?
Hisoka
Experienced poster
Posts: 120
Joined: Wed Mar 05, 2003 10:40 am
Location: Indonesia

Post by Hisoka »

hello titid, I think your problem only in your input.

Code: Select all

while (len != 7) {
         number[len++] = ch;
         ch = getchar();
      }
If you use this your output not same with your input.

Code: Select all

123-1233 => input
123-123 =>output
bye....... :wink:
titid_gede
Experienced poster
Posts: 187
Joined: Wed Dec 11, 2002 2:03 pm
Location: Mount Papandayan, Garut

Post by titid_gede »

got AC now, thank you very much pak evan :) :) :)
Kalo mau kaya, buat apa sekolah?
Nikolay Archak
New poster
Posts: 6
Joined: Tue Dec 02, 2003 6:43 am
Contact:

145 WA

Post by Nikolay Archak »

Hi!

I tried to submit this program more than 30 times but always got WA.
Can anybody said me what is wrong?
Thanks in advance :-D

Code: Select all

#include<vector>
#include<string>
#include<set>
#include<map>
#include<list>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<queue>
#include<iterator>

#define q(x) #x
#define qq(x) #x[0]
 
#define fori(st, end) for (int i = ((int)(st)); i <= ((int)(end)); i++) 
#define forj(st, end) for (int j = ((int)(st)); j <= ((int)(end)); j++)
#define fork(st, end) for (int k = ((int)(st)); k <= ((int)(end)); k++)
#define forl(st, end) for (int l = ((int)(st)); l <= ((int)(end)); l++)
#define form(st, end) for (int m = ((int)(st)); m <= ((int)(end)); m++)
 
#define VECI  vector<int>
#define LISTI list<int>
 
#define VECS vector<string>
#define LISTS list<string>
 
#define VECD vector<double>
 
using namespace std;
typedef vector<int> veci;
typedef vector<double> vecd;
typedef vector<string> vecs;
typedef vector<char>   vecch;
typedef string str;
 
 
#define ITRI vector<int>::iterator
#define ITRS vector<string>::iterator
 
#define vp(vec, val) vec.push_back(val)    
#define vf(vec, val) find(vec.begin(), vec.end(), val)
#define vs(vec) sort(vec.begin(), vec.end())
#define ve(vec, val) (vf(vec, val) != vec.end())
#define va(vec) vec.begin(), vec.end()
#define vind(vec, val) (ve(vec, val) ? vf(vec, val) - vec.begin() : -1)
#define vins(vec, val) do { if (!ve(vec, val)) vp(vec, val); } while(0)
 
#define lint long long
 
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define DIST(x, y) ABS((x)-(y))

int tax[5][3] = {
	{ 10, 6, 2 },
	{ 25, 15, 5},
	{ 53, 33, 13},
	{ 87, 47, 17},
	{144, 80, 30}
};

int get_mins(int x1, int x2, int t1, int t2) {

	if (t2 == t1) if (x2 > x1) return (x2-x1); else return 24*60-(x1-x2);
	if (x2 < x1) return get_mins(x1, 24*60, t1, t2) + get_mins(0, x2, t1, t2);
	if (t2 < t1) return get_mins(x1, x2, t1, 24*60) + get_mins(x1, x2, 0, t2);
	
	if (max(x1, t1) >= min(x2, t2)) return 0;
	else return (min(x2, t2)-max(x1, t1));
}

#include <sstream>
 
int main(int argc, char *argv[]) {
	
	char c;
		
	cout.setf(ios::fixed);
	cout.precision(2);
	while (cin >> c) {
			
		string s1;
		int h1, m1, h2, m2;
		int t1, t2;
	
		if (c == '#') return 0;
		
		cin >> s1 >> h1 >>  m1 >> h2 >>  m2;
			
		if (h1 == 24) h1 = 0;
		if (h2 == 24) h2 = 0;
		
		t1 = h1*60+m1;
		t2 = h2*60+m2;
		
		int a1 = get_mins(8*60, 18*60, t1, t2);
		int a2 = get_mins(18*60, 22*60, t1, t2);
		int a3 = get_mins(22*60, 8*60, t1, t2); 
		
		int tot = a1*tax[c-'A'][0] + a2*tax[c-'A'][1] + a3*tax[c-'A'][2];
		
		
		cout.width(10);
      		cout<<s1;
      		cout.width(6);
      		cout<<a1;
      		cout.width(6);
      		cout<<a2;
      		cout.width(6);
      		cout<<a3;
      		cout.width(3);
      		cout<<c;
		cout.width(8);
		cout<<(tot*1.0)/100<<endl;
	}
	return 0;
}
chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Problem 145. Why WA?

Post by chunyi81 »

Below is my C program for problem 145. I have handled the 24 hr case and checked many times. But I still get WA. Can anyone tell me why? Thanks.

[c]#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define morn 480
#define eve 1080
#define night 1320

double calc_cost(int min1,int min2,int index);

const double cost[5][3] = {{0.1,0.06,0.02},{0.25,0.15,0.05},
{0.53,0.33,0.13},{0.87,0.47,0.17},{1.44,0.8,0.3}};

int main() {

char step[1];
char number[9];
int start_hr,start_min,end_hr,end_min,min1,min2;
int cat1,cat2,cat3;
double total_cost = 0.0;

while(scanf("%s",&step) == 1) {

if (strcmp(step,"#") == 0)
break;

else {

scanf("%s %d %d %d %d",&number,&start_hr,&start_min,&end_hr,&end_min);
min1 = start_hr * 60 + start_min;
min2 = end_hr * 60 + end_min;

switch(step[0]) {

case 'A':
total_cost = calc_cost(min1,min2,0);
break;

case 'B':
total_cost = calc_cost(min1,min2,1);
break;

case 'C':
total_cost = calc_cost(min1,min2,2);
break;

case 'D':
total_cost = calc_cost(min1,min2,3);
break;

case 'E':
total_cost = calc_cost(min1,min2,4);
break;

}

if ((min1 >= morn) && (min1 < eve)) {

if ((min2 >= morn) && (min2 < eve)) {

cat1 = min2 - min1;
cat2 = cat3 = 0;

}

else if ((min2 >= eve) && (min2 < night)) {

cat1 = eve - min1;
cat2 = min2 - eve;
cat3 = 0;

}

else {

cat1 = eve - min1;
cat2 = night - eve;

if (min2 - min1 > 0)
cat3 = min2 - night;

else
cat3 = 1440 - night + min2;

}

}

else if ((min1 >= eve) && (min1 < night)) {

if ((min2 >= morn) && (min2 < eve)) {

cat1 = min2 - morn;
cat2 = night - min1;
cat3 = 1440 - night + morn;

}

else if ((min2 >= eve) && (min2 < night)) {

cat2 = min2 - min1;
cat1 = cat3 = 0;

}

else {

cat1 = 0;
cat2 = night - min1;

if (min2 >= night)
cat3 = min2 - night;

else
cat3 = 1440 - night + min2;

}

}

else {

if ((min2 >= morn) && (min2 < eve)) {

if (min1 - 1320 >= 0)
cat3 = 1440 - min1 + morn;

else
cat3 = morn - min1;

cat1 = min2 - morn;
cat2 = 0;

}

else if ((min2 >= eve) && (min2 < night)) {

cat3 = 1440 - min1 + morn;
cat1 = eve - morn;
cat2 = min2 - eve;

}

else {

if (min2 - min1 > 0)
cat3 = min2 - min1;

else
cat3 = 1440 - min1 + min2;

cat1 = cat2 = 0;

}

}

if (min2 - min1 == 0) {
cat1 = cat3 = 600;
cat2 = 240;
}

printf("%10s%5d%7d%6d%3s%8.2lf\n",number,cat1,cat2,cat3,step,total_cost);

}

}

return 0;

}

double calc_cost(int min1,int min2,int index) {

double total_cost = 0.0;

if ((min1 >= morn) && (min1 < eve)) {

if ((min2 >= morn) && (min2 < eve))
total_cost += (min2 - min1) * cost[index][0];

else if ((min2 >= eve) && (min2 < night)) {

total_cost += (eve - min1) * cost[index][0];
total_cost += (min2 - eve) * cost[index][1];

}

else {
total_cost += (eve - min1) * cost[index][0];
total_cost += (night - eve) * cost[index][1];

if (min2 - min1 > 0)
total_cost += (min2 - night) * cost[index][2];

else {
total_cost += (1440 - night) * cost[index][2];
total_cost += (min2 * cost[index][2]);
}

}

}

else if ((min1 >= eve) && (min1 < night)) {

if ((min2 >= morn) && (min2 < eve)) {

total_cost += (night - min1) * cost[index][1];
total_cost += (1440 - night) * cost[index][2];
total_cost += (morn * cost[index][2]);
total_cost += (min2 - morn) * cost[index][0];

}

else if ((min2 >= eve) && (min2 < night))
total_cost += (min2 - min1) * cost[index][1];

else {
total_cost += (night - min1) * cost[index][1];

if (min2 - night >= 0)
total_cost += (min2 - night) * cost[index][2];

else {
total_cost += (1440 - night) * cost[index][2];
total_cost += (min2 * cost[index][2]);
}

}

}

else {

if ((min2 >= morn) && (min2 < eve)) {

if (min1 - 1320 >= 0) {
total_cost += (1440 - min1) * cost[index][2];
total_cost += (morn * cost[index][2]);
}

else
total_cost += (morn - min1) * cost[index][2];

total_cost += (min2 - morn) * cost[index][0];
}

else if ((min2 >= eve) && (min2 < night)) {
total_cost += (1440 - min1) * cost[index][2];
total_cost += (morn * cost[index][2]);
total_cost += (eve - morn) * cost[index][0];
total_cost += (min2 - eve) * cost[index][1];
}

else {

if (min2 - min1 > 0)
total_cost += (min2 - min1) * cost[index][2];

else {
total_cost += (1440 - min1) * cost[index][2];
total_cost += (min2 * cost[index][2]);
}

}

}

if (min2 - min1 == 0)
total_cost = 600 * cost[index][0] + 240 * cost[index][1] +
600 * cost[index][2];

return total_cost;

}[/c]
Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China

145 Why WA?Need some sample input:(

Post by Morning »

[cpp]
#include "iostream.h"
#include "stdio.h"
int readChar(char* s)
{
int n=0;
for(int loop=0;s[loop]!='\0';loop++)
{
n=n*10+s[loop]-48;
}
return n;
}
int main(int argc, char* argv[])
{
double charge[][4]={
{0.02,0.10,0.06,0.02},
{0.05,0.25,0.15,0.05},
{0.13,0.53,0.33,0.13},
{0.17,0.87,0.47,0.17},
{0.30,1.44,0.80,0.30}
};
int timeTable[]={8,18,22};
char number[20],x1[3],x2[3],x3[3],x4[3],distance;
int startH,startM,endH,endM,startT,endT,reverse,temp,toutput[4];
double count;
while(1)
{
cin>>distance;
if(distance=='#') break;
for(temp=0;temp<4;temp++)
toutput[temp]=0;
reverse=0;
cin>>number>>x1>>x2>>x3>>x4;
startH=readChar(x1);
startM=readChar(x2);
endH=readChar(x3);
endM=readChar(x4);

if(startH>endH || startH==endH && startM>endM)
{
reverse=1;
temp=startH;
startH=endH;
endH=temp;
temp=startM;
startM=endM;
endM=temp;
}
if(distance=='A') distance=0;
else
if(distance=='B') distance=1;
else
if(distance=='C') distance=2;
else
if(distance=='D') distance=3;
else
if(distance=='E') distance=4;
if(startH>=0 && startH<8) startT=0;
else
if(startH>=8 && startH<18) startT=1;
else
if(startH>=18 && startH<22) startT=2;
else
if(startH>=22 && startH<=24 || startH>=0 && startH<8) startT=3;
if(endH>=0 && endH<8) endT=0;
else
if(endH>=8 && endH<18) endT=1;
else
if(endH>=18 && endH<22) endT=2;
else
if(endH>=22 && endH<=24 || endH>=0 && endH<8) endT=3;
if(startT==endT)
{
toutput[startT]+=(endH-1-startH)*60+(60+endM-startM);
count=((endH-1-startH)*60+(60+endM-startM))*charge[distance][startT];
}
else
{
if(endT-startT==1)
{
toutput[startT]=(timeTable[startT]-1-startH)*60+(60-startM);
toutput[endT]=(endH-timeTable[startT])*60+endM;
count=((timeTable[startT]-1-startH)*60+(60-startM))*charge[distance][startT]+((endH-timeTable[startT])*60+endM)*charge[distance][startT+1];
}
else
{
if(endT-startT==2)
{
toutput[startT]=(timeTable[startT]-1-startH)*60+(60-startM);
toutput[startT+1]=(timeTable[startT+1]-timeTable[startT])*60;
toutput[endT]=(endH-timeTable[startT+1])*60+endM;
count=((timeTable[startT]-1-startH)*60+(60-startM))*charge[distance][startT]+(timeTable[startT+1]-timeTable[startT])*60*charge[distance][startT+1]+((endH-timeTable[startT+1])*60+endM)*charge[distance][startT+2];
}
else
{
toutput[startT]=8*60-startH*60;
toutput[startT+1]=10*60;
toutput[startT+2]=4*60;
toutput[endT]=(endH-1-22)*60+60-endM;
count=8*60*charge[distance][0]+10*60*charge[distance][1]+4*60*charge[distance][2]+2*60*charge[distance][3]-(startH*60*charge[distance][0]+((24-1-endH)*60+60-endM)*charge[distance][3]);
}
}
}
if(reverse==1)
{
count=8*60*charge[distance][0]+10*60*charge[distance][1]+4*60*charge[distance][2]+2*60*charge[distance][3]-count;
toutput[0]=8*60-toutput[0];
toutput[1]=10*60-toutput[1];
toutput[2]=4*60-toutput[2];
toutput[3]=2*60-toutput[3];
reverse=0;
}
if(count==0.00)
{
count=8*60*charge[distance][0]+10*60*charge[distance][1]+4*60*charge[distance][2]+2*60*charge[distance][3];
toutput[0]=8*60;
toutput[1]=10*60;
toutput[2]=4*60;
toutput[3]=2*60;
}
printf("%10s%6d%6d%6d%3c%8.2lf\n",number,toutput[1],toutput[2],toutput[0]+toutput[3],distance+65,count);
}
return 0;
}

[/cpp]
"Learning without thought is useless;thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Post by sohel »

I am also getting wrong answer, eventhough the problem seems straight forward.
Are there any critical inputs?
Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China

Post by Morning »

Seems not.My friends send his AC code to me.I've send it to u:)hope u can find where u problem is
"Learning without thought is useless;thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Post by sohel »

Thanks!
El-idioto
New poster
Posts: 45
Joined: Mon Jul 14, 2003 9:42 pm
Location: Zoetermeer, The Netherlands

Post by El-idioto »

Hi all,

I'm getting totaly sick of this problem. :x
I keep getting WA! Is there any sneaky input possible? This problem is extremely easy, yet I cannot get accepted.

Can somebody who has an AC program check their input with my code?
Maybe it has to do with the fact that I don't use GCC as a compiler.

[cpp]// @JUDGE_ID: 33444KK 145 C++
//
// 145_GondwanalandTelecom: Create a phone bill from phone records
//

#include <cstdio>

// The base types
#ifdef WIN32
typedef __int8 int8;
typedef __int16 int16;
typedef __int32 int32;
typedef __int64 int64;
typedef unsigned __int8 uint8;
typedef unsigned __int16 uint16;
typedef unsigned __int32 uint32;
typedef unsigned __int64 uint64;
#else
typedef char int8;
typedef short int16;
typedef long int32;
typedef long long int int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned long uint32;
typedef unsigned long long int uint64;
#endif

// This function returns the smaller of the two elements
template <class T> T Min(T tA, T tB)
{
return tA < tB ? tA : tB;
}

// This function returns the bigger of the two elements
template <class T> T Max(T tA, T tB)
{
return tA > tB ? tA : tB;
}

// Pre-calculated minutes
#define MINUTES_PER_DAY (60 * 24)

#define NIGHT_RATE_1_START int32(-2 * 60)
#define NIGHT_RATE_1_END int32( 8 * 60)
#define DAY_RATE_1_START int32( 8 * 60)
#define DAY_RATE_1_END int32(18 * 60)
#define EVENING_RATE_1_START int32(18 * 60)
#define EVENING_RATE_1_END int32(22 * 60)
#define NIGHT_RATE_2_START int32(22 * 60)
#define NIGHT_RATE_2_END int32(32 * 60)
#define DAY_RATE_2_START int32(32 * 60)
#define DAY_RATE_2_END int32(42 * 60)
#define EVENING_RATE_2_START int32(42 * 60)
#define EVENING_RATE_2_END int32(46 * 60)
#define NIGHT_RATE_3_START int32(46 * 60)
#define NIGHT_RATE_3_END int32(56 * 60)

// The call rates (step A through E)
double ppRates[5][3] =
{
0.10, 0.06, 0.02,
0.25, 0.15, 0.05,
0.53, 0.33, 0.13,
0.87, 0.47, 0.17,
1.44, 0.80, 0.30
};


//-------------------------------------------------------------------
// F U N C T I O N S
//-------------------------------------------------------------------


// This function is the entrance of the app
int main()
{
int8 pi8ChargingStep[2], pi8PhoneNumber[9];
int16 i16HourStart, i16MinuteStart, i16HourEnd, i16MinuteEnd;

// Get the next call
while(scanf("%s %s %hi %hi %hi %hi", pi8ChargingStep, pi8PhoneNumber, &i16HourStart, &i16MinuteStart, &i16HourEnd, &i16MinuteEnd) == 6)
{
double dTotCost;
int32 i32Start, i32End, i32TotDay = 0, i32TotEvening = 0, i32TotNight = 0;

// Convert the times to minutes
i32Start = 60 * i16HourStart + i16MinuteStart;
i32End = 60 * i16HourEnd + i16MinuteEnd;

// Is the end time before the start time?
if(i32End <= i32Start)
i32End += MINUTES_PER_DAY;

// Count the minutes in the night rate
if(i32Start < NIGHT_RATE_1_END && i32End >= NIGHT_RATE_1_START)
i32TotNight += Min(NIGHT_RATE_1_END, i32End) - Max(NIGHT_RATE_1_START, i32Start);
if(i32Start < NIGHT_RATE_2_END && i32End >= NIGHT_RATE_2_START)
i32TotNight += Min(NIGHT_RATE_2_END, i32End) - Max(NIGHT_RATE_2_START, i32Start);
if(i32Start < NIGHT_RATE_3_END && i32End >= NIGHT_RATE_3_START)
i32TotNight += Min(NIGHT_RATE_3_END, i32End) - Max(NIGHT_RATE_3_START, i32Start);

// Count the minutes in the day rate
if(i32Start < DAY_RATE_1_END && i32End >= DAY_RATE_1_START)
i32TotDay += Min(DAY_RATE_1_END, i32End) - Max(DAY_RATE_1_START, i32Start);
if(i32Start < DAY_RATE_2_END && i32End >= DAY_RATE_2_START)
i32TotDay += Min(DAY_RATE_2_END, i32End) - Max(DAY_RATE_2_START, i32Start);

// Count the minutes in the evening rate
if(i32Start < EVENING_RATE_1_END && i32End >= EVENING_RATE_1_START)
i32TotEvening += Min(EVENING_RATE_1_END, i32End) - Max(EVENING_RATE_1_START, i32Start);
if(i32Start < EVENING_RATE_2_END && i32End >= EVENING_RATE_2_START)
i32TotEvening += Min(EVENING_RATE_2_END, i32End) - Max(EVENING_RATE_2_START, i32Start);

// Calculate the call's total cost
dTotCost = ppRates[pi8ChargingStep[0] - 'A'][0] * i32TotDay +
ppRates[pi8ChargingStep[0] - 'A'][1] * i32TotEvening +
ppRates[pi8ChargingStep[0] - 'A'][2] * i32TotNight;

// Show the call cost
printf("%10s%6i%6i%6i%3s%8.2lf\n",
pi8PhoneNumber, i32TotDay, i32TotEvening, i32TotNight, pi8ChargingStep, dTotCost);
}

return 0;
}[/cpp]
Post Reply

Return to “Volume 1 (100-199)”