int main(){
	int t;
	while(scanf("%d", &t) > 0){
		int i, x, y;
		char op[10];
		for(i = 0; i < 30001; i++)
			top[i] = down[i] = Fdown[i] = Ftop[i] = i, ct[i] = 0;
		while(t--){
			scanf("%s", op);
			if(op[0] == 'M'){
				scanf("%d%d", &x, &y);
				int ftop = find_top(y), fdown = find_down(x);
				if(find_top(x) != ftop){
					down[fdown] = ftop;
					top[ftop] = fdown;
					Fdown[fdown] = ftop;
					Ftop[ftop] = fdown;
				}
			}
			else{
				scanf("%d", &x);
				printf("%d\n", ct[x]);
			}
		}
	}
	return 0;
}
示例#2
0
//********************************************************
void WordsEdit::do_add_word(void)
{
 
  QString str = lineword->text();
  char *word = (char *)str.latin1();
  
  FindLastWord = 0;
  FindLastGroup = 0;
  int curgroup = listgroup->currentItem();
  if(find_down(word)){
    sprintf(tmp,"This word already exists (in group %d).\nDo you wish to remove this occurance and add it to this group ?",wordlist->WordGroup[FindLastGroup].GroupNum);
    
    switch( QMessageBox::information( this, "Remove duplicate word ?",
                                      tmp,
                                      "Yes", "No", 
                                      0,      // Enter == button 0
                                      1 ) ) { // Escape == button 1
    case 0: //yes
      wordlist->WordGroup[FindLastGroup].Words.del(FindLastWord);
      update_group(FindLastGroup);
      changed=true;
      break;
    case 1: //no
      return;
    }
  }

  wordlist->WordGroup[curgroup].Words.addsorted(word); 
  changed=true;
  select_group(curgroup);
  update_group(curgroup);

}
示例#3
0
//********************************************************
void WordsFind::find_next_cb()
{
  int ret;
  QString str = find_field->text();
  char *word = (char *)str.latin1();

  if(FindLastGroup==-1||FindLastWord==-1){
    find_first_cb();
    return;
  }

  if(down->isChecked()){
    if(FindLastWord+1 >= wordlist->WordGroup[FindLastGroup].Words.num){
      if(FindLastGroup+1 >= wordlist->NumGroups){        
        menu->errmes("Find","'%s' not found !",word);    
        return ;
      }
      else{
        FindLastWord = 0;
        FindLastGroup++;    
      }
    }
    else{
      FindLastWord++;
    }         
    ret = find_down(word);
  }
  else{
    if(FindLastWord -1 < 0){
      if(FindLastGroup-1 < 0){        
        menu->errmes("Find","'%s' not found !",word);    
        return;
      }
      else{
        FindLastGroup--;
        FindLastWord = wordlist->WordGroup[FindLastGroup].Words.num-1;
      }
    }
    else{
      FindLastWord--;
    }  
    ret = find_up(word);
  }
 
  if(ret){
    wordsedit->listgroup->setCurrentItem(FindLastGroup);
    wordsedit->listwords->setCurrentItem(FindLastWord);
  }
  else{
    menu->errmes("Find","'%s' not found !",word);    
  }

}
示例#4
0
//********************************************************
void WordsFind::find_first_cb()
{
  int ret;
  QString str = find_field->text();
  char *word = (char *)str.latin1();

  if(down->isChecked()){
    if(start->isChecked()){
      FindLastGroup=0;
      FindLastWord=0;
    }
    else{
      if(wordsedit->listgroup->currentItem()!=-1)
        FindLastGroup=wordsedit->listgroup->currentItem();
      else
        FindLastGroup=0;
      if(wordsedit->listwords->currentItem()!=-1)
        FindLastWord=wordsedit->listwords->currentItem();
      else
        FindLastWord=0;
    }
    ret = find_down(word);
  }
  else{    
    if(start->isChecked()){
      FindLastGroup=wordlist->NumGroups -1;
      FindLastWord = wordlist->WordGroup[FindLastGroup].Words.num-1;
    }
    else{
      if(wordsedit->listgroup->currentItem()!=-1)
        FindLastGroup=wordsedit->listgroup->currentItem();
      else
        FindLastGroup=wordlist->NumGroups -1;
      if(wordsedit->listwords->currentItem()!=-1)
        FindLastWord=wordsedit->listwords->currentItem();
      else
        FindLastWord=wordlist->WordGroup[FindLastGroup].Words.num-1;            
    }
    ret = find_up(word);
  }
  
  if(ret){
    wordsedit->listgroup->setCurrentItem(FindLastGroup);
    wordsedit->listwords->setCurrentItem(FindLastWord);
  }
  else{
    menu->errmes("Find","'%s' not found !",word);
  }
  
}
示例#5
0
void hexbright::update() {
  unsigned long now;

#if (DEBUG==DEBUG_LOOP)
  unsigned long start_time=micros();
#endif


#ifdef STROBE  
  while (true) {
    do {
      now = micros();
    } while (next_strobe > now && // not ready for strobe
	     continue_time > now); // not ready for update

    if (next_strobe <= now) {
      if (now - next_strobe <26) {
	digitalWriteFast(DPIN_DRV_EN, HIGH);
	delayMicroseconds(strobe_duration);
	digitalWriteFast(DPIN_DRV_EN, LOW);
      }
      next_strobe += strobe_delay;
    }
    if(continue_time <= now) {
      if(strobe_delay>update_delay && // we strobe less than once every 8333 microseconds
	 next_strobe-continue_time < 4000) // and the next strobe is within 4000 microseconds (may occur before we return)
	continue;
      else
	break;
    }
  } // do nothing... (will short circuit once every 70 minutes (micros maxint))
#else
    do {
      now = micros();
    } while (continue_time > now); // not ready for update
#endif  

  // if we're in debug mode, let us know if our loops are too large
#if (DEBUG!=DEBUG_OFF && DEBUG!=DEBUG_PRINT)
  static int i=0;
#if (DEBUG==DEBUG_LOOP)
  static unsigned long last_time = 0;
  if(!i) {
    Serial.print("Time used: ");
    Serial.print(start_time-last_time);
    Serial.println("/8333");
  }
  last_time = now;
#endif
  if(now-continue_time>5000 && !i) {
    // This may be caused by too much processing for our update_delay, or by too many print statements)
    //  If you're triggering this, your button and light will react more slowly, and some accelerometer
    //  data is being missed.
    Serial.println("WARNING: code is too slow");
  }
  if (!i)
    i=1000/update_delay; // display loop output every second
  else
    i--;
#endif
  
  
  // power saving modes described here: http://www.atmel.com/Images/2545s.pdf
  //run overheat protection, time display, track battery usage
  
#ifdef LED
  // regardless of desired led state, turn it off so we can read the button
  _led_off(RLED);
  delayMicroseconds(50); // let the light stabilize...
  read_button();
  // turn on (or off) the leds, if appropriate
  adjust_leds();
#ifdef PRINT_NUMBER
  update_number();
#endif
#else
  read_button();
#endif
  
  read_thermal_sensor(); // takes about .2 ms to execute (fairly long, relative to the other steps)
  read_charge_state();
  read_avr_voltage();

#ifdef ACCELEROMETER
  read_accelerometer();
  find_down();
#endif
  detect_overheating();
  detect_low_battery();
  apply_max_light_level();
  
  // change light levels as requested
  adjust_light();


  // advance time at the same rate as values are changed in the accelerometer.
  //  advance continue_time here, so the first run through short-circuits, 
  //  meaning we will read hardware immediately after power on.
  continue_time = continue_time+(1000*update_delay);
}
示例#6
0
void hexbright::update() {
  // advance time at the same rate as values are changed in the accelerometer.
  continue_time = continue_time+(1000*update_delay);
  
  unsigned long now;
  while (true) {
    do {
      now = micros();
    } while (next_strobe > now && // not ready for strobe
	     continue_time > now); // not ready for update
     
    if (next_strobe <= now) {
      if (now - next_strobe <26) {
	digitalWrite(DPIN_DRV_EN, HIGH);
	delayMicroseconds(strobe_duration);
	digitalWrite(DPIN_DRV_EN, LOW);
      }
      next_strobe += strobe_delay;
    }
    if(continue_time <= now) {
      if(strobe_delay>update_delay && // we strobe less than once every 8333 microseconds
	 next_strobe-continue_time < 4000) // and the next strobe is within 4000 microseconds (may occur before we return)
	continue;
      else
	break;
    }
  } // do nothing... (will short circuit once every 70 minutes (micros maxint))

  // if we're in debug mode, let us know if our loops are too large
#if (DEBUG!=DEBUG_OFF)
  static int i=0;
  static float avg_loop_time = 0;
  static float last_time = 0;
  avg_loop_time = (avg_loop_time*29 + continue_time-last_time)/30;
#if (DEBUG==DEBUG_LOOP)
  if(!i) {
    Serial.print("Average loop time: ");
    Serial.println(avg_loop_time/1000);
  }
#endif
  if(avg_loop_time/1000>update_delay+1 && !i) {
    // This may be caused by too much processing for our update_delay, or by too many print statements (each one takes a few ms)
    Serial.print("WARNING: loop time: ");
    Serial.println(avg_loop_time/1000);
  }
  if (!i)
    i=1000/update_delay; // display loop output every second
  else
    i--;
  last_time = continue_time;
#endif


  // power saving modes described here: http://www.atmel.com/Images/2545s.pdf
  //run overheat protection, time display, track battery usage

  #ifdef LED
  // regardless of desired led state, turn it off so we can read the button
  _led_off(RLED);
  delayMicroseconds(50); // let the light stabilize...
  read_button();
  // turn on (or off) the leds, if appropriate
  adjust_leds();
#ifdef PRINT_NUMBER
  update_number();
#endif
#else
  read_button();
#endif

  read_thermal_sensor(); // takes about .2 ms to execute (fairly long, relative to the other steps)
#ifdef ACCELEROMETER
  read_accelerometer();
  find_down();
#endif
  overheat_protection();

  // change light levels as requested
  adjust_light();
}
int find_down(int x){
	return x == Fdown[x] ? x : (Fdown[x] = find_down(Fdown[x]));
}