Esempio n. 1
0
//WHY CALLING REMOVE NODE HERE?
void AVL_Tree::findCity(Node* n, int x, int y)
{
	if(n!=NULL){
		if(n->getXCoordinate()==x && n->getYCoordinate()==y){
			removeCity(n);
		}
		findCity(n->getLeft(), x, y);
		findCity(n->getRight(), x, y);
	}
}//end findCity
Esempio n. 2
0
void drawRoadBetween(int n, int n2){
	City c1 = findCity(n);
	City c2 = findCity(n2);

	int * colors1 = getColor(c1->num);
	int * colors2 = getColor(c2->num);

	int xC1 = c1->x + (size + size/20)/2;
	int yC1 = c1->y + (size + size/20)/2;
	int xC2 = c2->x + (size + size/20)/2;
	int yC2 = c2->y + (size + size/20)/2;

	drawLines(xC1, yC1, xC2, yC2, *(colors1), *(colors1 + 1), *(colors1 + 2));
	drawLines(xC1+3, yC1+3, xC2+3, yC2+3, *(colors2), *(colors2 + 1), *(colors2 + 2));

	free(colors1);
	free(colors2);
}
Esempio n. 3
0
int main(int argc, char** argv){
  int listenfd,connfd,n;
  int count =0;
  pid_t childpid;
  socklen_t clilen;
  char buf[MAXLINE];
  struct sockaddr_in cliaddr,servaddr;
  struct sendLine* recvline;

  if((listenfd = socket(AF_INET,SOCK_STREAM,0))<0){
    perror("failed to create socket");
    exit(errno);    
  }

  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  servaddr.sin_port = htons(SERVER_PORT);

  bind(listenfd,(struct sockaddr*)&servaddr,sizeof(servaddr));
  listen(listenfd,LISTENQ);
  printf("%s\n","server is running...waiting for connecting!");  
  for(;;){
    count++;
    clilen = sizeof(cliaddr);
    connfd = accept(listenfd,(struct sockaddr*)&cliaddr,&clilen);    
    printf("%s\n", "received request....");

    if((childpid = fork())==0){                  
      printf("child created to process the client request\n");
      close(listenfd);

      struct WeathMsg weathmsg;      
      struct recvLine sendline;
      char dayNum;            
      char sign[3];      
      sign[2]='\0';
      while((n=recv(connfd,buf,MAXLINE,0))>0){        
        recvline = (struct sendLine*)buf;
        
        bzero(&weathmsg,sizeof(weathmsg));
        memset(sign,0x00,2);
        dayNum = 0x00;        

        /*processing*/                                        
        if(recvline->lineHead[0]==0x01){    //comes the city name
          if(findCity(recvline->city)==1){  //have msg about the msg
            sign[0]=0x03;
            sign[1]=0x00;
            sendline = makeMsg(weathmsg,recvline->city,0x00,sign,0);
            send(connfd,(char*)&sendline,sizeof(sendline),0);
          }
          else{                             // don't have msg about the city
            sign[0]=0x04;            
            sign[1]=0x00;
            sendline = makeMsg(weathmsg,recvline->city,0x00,sign,0);
            send(connfd,(char*)&sendline,sizeof(sendline),0);
          }
        }
        else{
          int sendNum;    // one day or three day
          if(recvline->lineHead[1]==0x01){      // one day's weather msg                                
            sign[1]=0x41;          
            sendNum=0;            
            if(recvline->lineTail < 0x06){
              sign[0]=0x01;   
            }
            else{
              sign[0]=0x02; 
            }
          }
          else{                                 // three day's weather msg                    
            sign[0]=0x01; sign[1]=0x42;            
            sendNum=3;
          }
          weathmsg = randWeath();
            
          dayNum = recvline->lineTail;
          sendline = makeMsg(weathmsg,recvline->city,dayNum,sign,sendNum);                          
          send(connfd,(char*)&sendline,sizeof(sendline),0);
          printf("send a weather forecast message to the client %d...\n",count);
        }
        /*proessingh*/

        memset(recvline,0,strlen((char*)recvline));
        memset(buf,0,MAXLINE);
      }    
      if(n<0){
        printf("%s\n", "read error");                    
      }            
      printf("Connect %d terminated... \n", count);          
      exit(0);      
    }    
    close(connfd);    
  }
}
Esempio n. 4
0
void AVL_Tree::deleteCityByCoordinates(int x, int y)
{
	findCity(m_root, x, y);
	std::cout<<"Attempted to remove city at ("<< x <<", "<< y <<")\n";
}//end deleteCoordinates
Esempio n. 5
0
File: dusk.C Progetto: cen5bin/acm
int main()
{
  FILE *in = fopen( "dusk.in", "r" );
  int  i, j;
  int  num;
  int  fall=1;

  fscanf( in, "%d", &num );

  while( num-- )
    {
      int nConnections;

      printf("Test Case %d.\n", fall++ );

      // --- read input ---
      fscanf( in, "%d", &nConnections );
      
      i       = 0;
      nCities = 0;
      for( j=0; j<nConnections; j++ ) // read input and omit false routes
	{
	  char buffer1[32], buffer2[32];
	  int  travelTime;

	  fscanf( in, "%s %s %d %d", 
		  buffer1, 
		  buffer2, 
		  &(connections[i].fromTime),
		  &travelTime );

	  connections[i].from = findCity( buffer1 );
	  connections[i].to   = findCity( buffer2 );

	  if( travelTime > 12 )
	    continue;

	  if( connections[i].fromTime >= 6 && 
	      connections[i].fromTime <  18  )
	    continue;

	  if( (connections[i].fromTime+travelTime) % 24 > 6 && 
	      (connections[i].fromTime+travelTime) % 24 < 18  )
	    continue;

	  connections[i].fromTime -= 18; // 18.00 is hour 0
	  if( connections[i].fromTime < 0 )
	    connections[i].fromTime += 24;

	  connections[i].toTime = connections[i].fromTime +travelTime ;
	  i++;
	}

      nConnections = i;

      // --- initialize ---
      for( i=0; i<nCities; i++ )
	cityTimes[i] = oo;
      
      char buffer[32];
      fscanf( in, "%s", buffer );
      cityTimes[ findCity(buffer) ] = 0;

      for( i=0; i<nCities; i++ )
	for( j=0; j<nConnections; j++ )
	  relax( j );
      
      fscanf( in, "%s", buffer );
      i = cityTimes[findCity(buffer)];

      if( i==oo )
	printf( "There is no route Vladimir can take.\n" );
      else
	printf( "Vladimir needs %d litre(s) of blood.\n", i/24 );

      /* for( i=0; i<nCities; i++ )
	 printf( "Time %s: %d\n", cities[i], cityTimes[i] ); */
      
    }

  fclose( in );

  return 0;
}