int main(int argc, const char * argv[]) {
	
	int testCases;
	int child, mother;
	
#ifdef FILEIO
	if((infile = fopen("input.txt", "r"))==NULL) exit(1);;
	fscanf(infile, "%d", &testCases);
#else
	scanf("%d", &testCases);
#endif
	
	while (testCases-->0) {
		
#ifdef FILEIO
		fscanf(infile, "%d %d", &child, &mother);
#else
		scanf("%d %d", &child, &mother);
#endif
		
		printf("%llu\n", henry(child, mother, 2));
		
	}
	
    return 0;
}
Exemple #2
0
int main()
{
   fred();
   joe();
   henry();

   return 0;
}
/*
 int henry(int child, int mother)
 
 -	분모를 받아 핸리분수의 가장 큰 분모수를 반환한다.
	방법은 다음과 같다.
 
	1) 1/2부터 분모를 1씩 늘리며 차근차근 비교
	2) 현재 분수와 비교, 작으면 그 분수를 택한다.
	3) 여기서 두 경우로 나뉜다.
		basecase - 분자가 1이면 여기서의 분모 값을 반환
		rcurstep - 그 외엔 다시 핸리를 굴린다
 
 */
unsigned long long henry (unsigned long long child, unsigned long long mother, unsigned long long mkHenryNum) {

	// 이 부분을 수정
	mkHenryNum = mother/child ;
	while (child*(mkHenryNum) < mother){
		// printf("."); // yoon // for count calcCnt
		mkHenryNum++;
	}
	
	child = (child*mkHenryNum) - mother;
	mother *= mkHenryNum;
	
#ifdef CONSOLE
	printf(">> sub 1/%llu, %llu/%lluleft\n", mkHenryNum, child, mother);
#endif
	
	if (child == 1) return mother ; // basecase
	else if (child == 0) return mkHenryNum; // yoon // basecase // 아까 뺀게 1
	return henry(child, mother, mkHenryNum+1); // recur step
}
int main() {

  std::cout << "start of main" << std::endl;

  // ====================================================
  // SINGLE OWNER SMART POINTERS
  // ====================================================

  // first, without smart pointers!
  Balloon* alice(new Balloon("Hello Kitty"));

  // now, with our homemade single owner smart pointer
  dsAutoPtr<Balloon> bob(new Balloon("Spiderman"));

  // both alice & bob work like regular pointers...
  alice->print();
  bob->print();



  //
  // CHECKPOINT 2A: INSERT NECESSARY EXPLICIT DEALLOCATION
  //
  delete alice;



  // ====================================================
  // SIMPLE SHARED POINTERS
  // ====================================================

  // first, without smart pointers
  Balloon* cathy(new Balloon("Buzz Lightyear"));
  Balloon* daniel(cathy);
  Balloon* elaine(new Balloon("Pokemon"));
  Balloon* fred(elaine);
  daniel = fred;
  fred = NULL;
  elaine = cathy;
  cathy = NULL;



  //
  // CHECKPOINT 2B: INSERT NECESSARY EXPLICIT DEALLOCATION
  //
  delete elaine;
  delete daniel;

  daniel = NULL;
  elaine = NULL;


  // now, with our homemade shared pointer
  dsSharedPtr<Balloon> cathy2(new Balloon("Buzz Lightyear2"));
  dsSharedPtr<Balloon> daniel2(cathy2);
  dsSharedPtr<Balloon> elaine2(new Balloon("Pokemon2"));
  dsSharedPtr<Balloon> fred2(elaine2);
  daniel2 = fred2;
  fred2 = NULL;
  elaine2 = cathy2;
  cathy2 = NULL;
   // NOTE:  no explicit destruction required!
  daniel2 = NULL;
  elaine2 = NULL;


  // ====================================================
  // SHARED POINTERS WITH INTERCONNECTED STRUCTURES
  // ====================================================

  dsSharedPtr<Balloon> georgette(new Balloon("Mr Potato Head"));
  dsSharedPtr<Balloon> henry(new Balloon("Snoopy"));

  georgette->addRope2(henry);
  henry = new Balloon("Tigger");
  georgette->addRope2(henry);
  georgette->print2();
  henry->print2();

  dsSharedPtr<Balloon> isabelle(new Balloon("Shrek"));
  henry->addRope2(isabelle);
  isabelle = new Balloon("Barney the Purple Dinosaur");
  georgette->addRope2(isabelle);

  henry->print2();
  georgette->print2();
  isabelle->print2();


  //
  // CHECKPOINT 2C: REWRITE THE ABOVE EXAMPLE TO USE SHARED POINTERS
  //



  // ====================================================
  // CYCLIC STRUCTURES
  // ====================================================


  // FOR CHECKPOINT 3



  Balloon* jacob(new Balloon("Dora the Explorer"));
  Balloon* katherine(new Balloon("Kung Fu Panda"));
  Balloon* larry(new Balloon("Scooby Doo"));
  Balloon* miranda(new Balloon("SpongeBob SquarePants"));
  Balloon* nicole(new Balloon("Papa Smurf"));

  jacob->addRope(katherine);
  katherine->addRope(larry);
  larry->addRope(jacob);
  miranda->addRope(jacob);
  nicole->addRope(miranda);
  larry->addRope(nicole);

  katherine = NULL;
  larry = NULL;
  miranda = NULL;
  nicole = NULL;

  // jacob points to a cyclic structure!

  // to cleanup this structure:
  deleteAll(jacob);
  //delete jacob;

  jacob = NULL;




  std::cout << "end of main" << std::endl;
  return 0;

  //
  // NOTE: when smart pointers go out of scope, the destructors for
  //       those objects will be called automatically
  //
}