'분류 전체보기'에 해당되는 글 142건

  1. 2011.01.22 C++ Builder 라는툴을 접해봤다.
  2. 2011.01.13 나머지 연산자의 동작. 2
  3. 2011.01.13 strlen 따라잡기 in KLDP.ORG
  4. 2011.01.08 Queue
  5. 2011.01.08 Little Bishops
  6. 2011.01.07 순열
  7. 2011.01.07 부분집합
  8. 2011.01.07 soccer UVA
  9. 2011.01.05 Bridge
  10. 2011.01.02 Vito's Family
  11. 2011.01.01 Erdos Numbers
  12. 2010.12.31 123
  13. 2010.10.24 zumdahl 7th 화학 솔루션
  14. 2010.10.17 물리 8th solution
  15. 2010.09.24 방학 때 까지 인터넷 활동은 잠시 중단... 1

C++ Builder 라는툴을 접해봤다.

컴퓨터 이야기 2011. 1. 22. 11:20

MFC 보다 훨씬 쓰기 간편하다.

C++ 을 그대로 쓸 수 있는 강력함과 편한 GUI 프로그래밍 환경.

'컴퓨터 이야기' 카테고리의 다른 글

파이썬  (0) 2011.04.28
카드 게임 소스작성.  (0) 2011.04.14
라인 트레이서 중간 점검  (0) 2010.09.02
YOU JUST ACTIVATED MY TRAP CARD  (1) 2010.07.22
오랜만에 MSDN 들어가보니 많이 바꼈네요.  (0) 2010.07.17
:

나머지 연산자의 동작.

컴퓨터 이야기/C++ 2011. 1. 13. 03:27

예전에 KLDP에 음수에 대한 나머지 연산질문을 올린적이 있었다. 허접한 질문에도 불구하고 성심성의껏 다들 댓글을 달아주셨다.

------------------------------------------------------------------------------------------------------------------------------------------

나머지 연산자를 쓰다가 음수를 생각하게 되었습니다.

예를 들어서 (-3) % 2 는 1 이 될 수도 있고 -1 이 될 수도 있는거 같습니다. 한번 궁금해서 여러 프로그램에 이 식을 넣고 답을 기다렸습니다.

먼저 MS 의 VC는 답을 -1 로 내놓았습니다.
윈도우즈 내장 계산기는 답을 -1 로 내놓았습니다.

하지만, MS Excel 은 답을 1 로 내놓았습니다...

뭐가 정답일까요?

셋다 MS 제품인데 말이죠. 글 올리기전에 검색 해봤으나 찾지 못하고 글 올립니다. (__)




자세한 내용 : http://kldp.org/node/55978

'컴퓨터 이야기 > C++' 카테고리의 다른 글

boost::pool 메모리 풀  (0) 2015.12.09
C++ Standard draft 07  (0) 2011.02.05
strlen 따라잡기 in KLDP.ORG  (0) 2011.01.13
Queue  (0) 2011.01.08
Little Bishops  (0) 2011.01.08
:

strlen 따라잡기 in KLDP.ORG

컴퓨터 이야기/C++ 2011. 1. 13. 03:25

[옛날 쓴글 가져오기 - mmoz]

제가 간단히 아는 ㅇ명령어로만 해봤는데 결과가 아주 비참하군요!!

셀러론 1Ghz 입니다.

__declspec(naked) int mmojz_strlen(const char* s)
{
	__asm
	{
		push ebp
		mov ebp, esp
	}
	__asm
	{
		push ecx
		push esi
		mov ecx, -1
		mov esi, dword ptr[ebp+8];
		cld
l:
		lodsb
		inc ecx
		cmp al, 0
		jne l
		mov eax, ecx
		pop esi
		pop ecx
	}
	__asm
	{
		pop ebp
		ret
	}
}

int mmojz2_strlen(const char* ch) 
{ 
	int i=0; 
	while (*ch++) i++; 
	return i; 
} 

int main()
{	
	unsigned int t;


	t = timeGetTime();
	for(volatile unsigned int i=0; i<10000000; i++)
	{
		strlen("345349534583495834958589358938595");
	}
	printf("라이브러리 : %d\n", timeGetTime()-t);

	t = timeGetTime();
	for(volatile unsigned int i=0; i<10000000; i++)
	{
		mmojz_strlen("345349534583495834958589358938595");
	}
	printf("허접 어셈 : %d\n", timeGetTime()-t);

	t = timeGetTime();
	for(volatile unsigned int i=0; i<10000000; i++)
	{
		mmojz2_strlen("345349534583495834958589358938595");
	}
	printf("C언어 : %d\n", timeGetTime()-t);
	return 0;
}

debug 버전에서는
라이브러리 : 1065
허접 어셈 : 2658
C언어 : 6016

Release 버전에서는
라이브러리 : 89
허접 어셈 : 2625
C언어 : 941

비참...


philossh wrote:
int asmstrlen(const char* ch)
{
	__asm
	{
		mov edi, dword ptr [ebp+8];
		xor al, al;
		mov ecx, -1;
      repne scasb;
		xor eax, eax;
		mov eax, -2;
		sub eax, ecx;
	}
}

은 Release 버전에서는 작동하지 않습니다. (.NET 2003 입니다.)


http://kldp.org/node/56157

BackSpace :: back
BackSpace :: back

'컴퓨터 이야기 > C++' 카테고리의 다른 글

C++ Standard draft 07  (0) 2011.02.05
나머지 연산자의 동작.  (2) 2011.01.13
Queue  (0) 2011.01.08
Little Bishops  (0) 2011.01.08
순열  (0) 2011.01.07
:

Queue

컴퓨터 이야기/C++ 2011. 1. 8. 14:50
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <limits>
using namespace std;


#ifdef mycom
ifstream fin("input");
#else
#define fin cin
#endif

vector<int> v;
vector<int> orders;
int N, P, R;

unsigned long long counter=0;
void back(int order)
{
 if(v.size() == orders.size())
 {
  vector<int> arr;
  for(int i=0; i<orders.size(); i++)
  {
   arr.push_back(v[orders[i]]);
  }
  int myp, myr;
  myp = myr = 0;
  for(int i=0; i<arr.size(); i++)
  {
   bool allsmall = true;
   for(int j=0; j<=i; j++)
   {
    if(arr[j] > arr[i])
    {
     allsmall = false;
     break;
    }
   }

   if(allsmall) // arr[i] 가 leftable 하다
   {
    myp++;
   }
  }
  if(myp != P)
   return;
  for(int i=arr.size()-1; i>=0; i--)
  {
   bool allsmall = true;
   for(int j=arr.size()-1; j>i; j--)
   {
    if(arr[j] > arr[i])
    {
     allsmall = false;
     break;
    }
   }

   if(allsmall) // arr[i] 가 rightable 하다
   {
    myr++;
   }
  }
  if(myr != R)
   return;

  counter++;

 }
 else
 {
  for(int i=0; i<v.size(); i++)
  {
   if( find(orders.begin(), orders.end(), i) == orders.end() )
   {
    vector<int> arr;
    for(int i=0; i<orders.size(); i++)
    {
     arr.push_back(v[orders[i]]);
    }
    int myp, myr;
    myp = myr = 0;
    for(int i=0; i<arr.size(); i++)
    {
     bool allsmall = true;
     for(int j=0; j<=i; j++)
     {
      if(arr[j] > arr[i])
      {
       allsmall = false;
       break;
      }
     }

     if(allsmall) // arr[i] 가 leftable 하다
     {
      myp++;
     }
    }
    if(myp > P)
     return;
    orders.push_back(i);
    back(i);
    orders.pop_back();
   }
  }
 }
}

int main()
{
 int mycase;
 fin >> mycase;

 while(fin >> N >> P >> R)
 {
  v.clear();
  for(int i=1; i<=N; i++)
  {
   v.push_back(i); 
  }
  counter = 0;
  back(0);
  cout << counter << endl;
 }

 

 

 return 0;
}


'컴퓨터 이야기 > C++' 카테고리의 다른 글

나머지 연산자의 동작.  (2) 2011.01.13
strlen 따라잡기 in KLDP.ORG  (0) 2011.01.13
Little Bishops  (0) 2011.01.08
순열  (0) 2011.01.07
부분집합  (0) 2011.01.07
:

Little Bishops

컴퓨터 이야기/C++ 2011. 1. 8. 01:57
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <limits>
using namespace std;


#ifdef mycom
ifstream fin("input");
#else
#define fin cin
#endif
char chess[100][100] = {0,};
int n, k;
long long total = 0;
bool possible(int y, int x)
{
 int newy = y;
 int newx = x;
 for( ; newy >= 0 && newx >= 0; newy--, newx--)
 {
  if(chess[newy][newx] == true)
  {
   return false;
  }
 }
 newy = y;
 newx = x;
 for( ; newy < n && newx < n; newy++, newx++)
 {
  if(chess[newy][newx] == true)
  {
   return false;
  }
 }
 newy = y;
 newx = x;
 for( ; newy < n && newx >= 0; newy++, newx--)
 {
  if(chess[newy][newx] == true)
  {
   return false;
  }
 }
 newy = y;
 newx = x;
 for( ; newy >= 0 && newx < n; newy--, newx++)
 {
  if(chess[newy][newx] == true)
  {
   return false;
  }
 }
 return true;
}

inline bool sizecompare(int _y, int _x, int __y, int __x)
{
 //_ 가 크면 true;
 if(_y != __y)
  return _y > __y;
 else if(_y == __y)
 {
  return _x > __x;
 }
}
void back(int selcount, int lasty, int lastx)
{
 if(selcount == k)
 {
  total++;
 }
 else
 {
  for(int y=0; y<n; y++)
  {
   for(int x=0; x<n; x++)
   {    
    if(sizecompare(y, x, lasty, lastx) && possible(y, x))
    {
     chess[y][x] = true;
     back(selcount+1, y, x);
     chess[y][x] = false;
    }
   }
  }
 }
}

int main()
{
 bool bfirst = true;
 while(fin >> n >> k && n != 0 && k != 0)
 {
  if(bfirst != true)
  {
   cout << endl;
  }
  bfirst = false;
  total = 0;
  back(0, -1, 0);
  cout << total;
 }
 return 0;
}


'컴퓨터 이야기 > C++' 카테고리의 다른 글

strlen 따라잡기 in KLDP.ORG  (0) 2011.01.13
Queue  (0) 2011.01.08
순열  (0) 2011.01.07
부분집합  (0) 2011.01.07
soccer UVA  (0) 2011.01.07
:

순열

컴퓨터 이야기/C++ 2011. 1. 7. 22:05
vector<int> v;
vector<char> select;
void back(int order)
{
 if(select.size() == v.size())
 {
  for(int i=0; i<select.size(); i++)
  {
    cout << v[select[i]] << ", ";
  }
  cout << endl;
 }
 else
 {
  for(int i=0; i<v.size(); i++)
  {
   if(find(select.begin(), select.end(), i) == select.end())
   {
    select.push_back(i);
    back(i);
    select.pop_back();
   }
  }
 }
}
int main()
{
 int arr[] = {1,2,3};
 v.assign(arr, arr+3);

 back(-1);
 return 0;
}


'컴퓨터 이야기 > C++' 카테고리의 다른 글

Queue  (0) 2011.01.08
Little Bishops  (0) 2011.01.08
부분집합  (0) 2011.01.07
soccer UVA  (0) 2011.01.07
Bridge  (0) 2011.01.05
:

부분집합

컴퓨터 이야기/C++ 2011. 1. 7. 21:58
vector<int> v;
vector<char> select;
void back(bool sel)
{
 if(select.size() == v.size())
 {
  for(int i=0; i<v.size(); i++)
  {
   if(select[i] == true)
    cout << v[i] << ", ";
  }
  cout << endl;
 }
 else
 {
  select.push_back(true);
  back(true);
  select.pop_back();

  select.push_back(false);
  back(false);
  select.pop_back();
 }
}
int main()
{
 int arr[] = {1,2,3};
 v.assign(arr, arr+3);

 back(0);
 return 0;
}


'컴퓨터 이야기 > C++' 카테고리의 다른 글

Little Bishops  (0) 2011.01.08
순열  (0) 2011.01.07
soccer UVA  (0) 2011.01.07
Bridge  (0) 2011.01.05
Vito's Family  (0) 2011.01.02
:

soccer UVA

컴퓨터 이야기/C++ 2011. 1. 7. 01:38
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <limits>
#include <ctime>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
using namespace std;

#ifdef mycom
ifstream fin("input");
#else
#define fin cin
#endif

class team
{
public:
 int score;
 int wincounter;
 int goaldiff;
 int manygoal;
 int gamecounter;
 string teamname;

 ////////////
 int drawcounter;
 int losecounter;
 int sibalgoal;
 team() { 
  score = 0;
  wincounter = 0;
  goaldiff = 0;
  manygoal = 0;
  gamecounter = 0;
  drawcounter=0;
  losecounter=0;
  sibalgoal=0;
 }
 
 bool operator<(const team& t) const
 {
  if(this->score == t.score)
  {
   if(this->wincounter == t.wincounter)
   {
    if(this->goaldiff == t.goaldiff)
    {
     if(this->manygoal == t.manygoal)
     {
      if(this->gamecounter == t.gamecounter)
      {
       char ateam[100];
       char bteam[100];
       strcpy(ateam, teamname.c_str());
       strcpy(bteam, t.teamname.c_str());
       for(int i=0; i<strlen(ateam); i++)
        ateam[i] = toupper(ateam[i]);
       for(int i=0; i<strlen(bteam); i++)
        bteam[i] = toupper(bteam[i]);
       string a = ateam;
       string b = bteam;
       return a > b;
      }
      else
      {
       return this->gamecounter > t.gamecounter;
      }
     }
     else
     {
      return this->manygoal < t.manygoal;
     }
    }
    else
    {
     return this->goaldiff < t.goaldiff;
    }
   }
   else
   {
    return this->wincounter < t.wincounter;
   }
  }
  else
  {
   return this->score < t.score;
  }
 }
};


int main()
{
 int N;
 
 fin >> N;
 fin.ignore(1024, '\n');
 for(int n=1; n<=N; n++)
 {
  int T;
  
  string tonorname;
  char temptonorname[1024];
  
  fin.getline(temptonorname, 1024);
  tonorname = temptonorname;
  fin >> T;
  fin.ignore(1024, '\n');
  vector<team> teams;
  for(int j=1; j<=T; j++)
  {
   char temp[1024];
   fin.getline(temp, 1024);
   team tempteam;
   tempteam.teamname = temp;
   teams.push_back(tempteam);
  }

  int G;
  fin >> G;
  fin.ignore(1024, '\n');
  for(int g=1; g<=G; g++)
  {
   char temp[1024];
   char* p;
   
   int Ascore, Bscore;
   string Aname;
   string Bname;
   fin.getline(temp, 1024);
   p = strtok(temp, "#");
   Aname = p;
   p = strtok(0, "@");
   Ascore = atoi(p);
   p = strtok(0, "#");
   Bscore = atoi(p);
   p = strtok(0, "#");
   Bname = p;
   for(vector<team>::iterator iter = teams.begin(); iter != teams.end(); ++iter)
   {
    if((*iter).teamname == Aname)
    {
     if(Ascore > Bscore)
     {
      iter->score += 3;
      iter->wincounter++;
     }
     else if(Ascore == Bscore)
     {
      iter->drawcounter++;
      iter->score += 1;
     }
     else
      iter->losecounter++;
     iter->sibalgoal += Bscore;
     iter->manygoal += Ascore;
     iter->gamecounter++;
     iter->goaldiff += Ascore - Bscore;
    }
    else if( (*iter).teamname == Bname)
    {
     if(Bscore > Ascore)
     {
      iter->score += 3;
      iter->wincounter++;
     }
     else if(Ascore == Bscore)
     {
      iter->score += 1;
      iter->drawcounter++;
     }
     else
      iter->losecounter++;
     iter->sibalgoal += Ascore;
     iter->manygoal += Bscore;
     iter->gamecounter++;
     iter->goaldiff += Bscore - Ascore;
    }
   }

  }
  sort(teams.rbegin(), teams.rend());
  cout << tonorname << endl;
  for(int i = 0; i<teams.size(); i++)
  {
   printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", 
    i+1,
    teams[i].teamname.c_str(),
    teams[i].score,
    teams[i].gamecounter, 
    teams[i].wincounter,
    teams[i].drawcounter,
    teams[i].losecounter,
    teams[i].goaldiff,
    teams[i].manygoal,
    teams[i].sibalgoal);
  }
  if(n != N)
   cout << endl;
 }
 return 0;
}


'컴퓨터 이야기 > C++' 카테고리의 다른 글

순열  (0) 2011.01.07
부분집합  (0) 2011.01.07
Bridge  (0) 2011.01.05
Vito's Family  (0) 2011.01.02
Erdos Numbers  (0) 2011.01.01
:

Bridge

컴퓨터 이야기/C++ 2011. 1. 5. 01:05
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <limits>
#include <time.h>
#include <set>
using namespace std;


#ifdef mycom
#include <fstream>
ifstream fin("input");
#else
#define fin cin
#endif

vector<int> A;
vector<int> B;

 

 


int main()
{
 int testcase;

 testcase = 1;
 fin >> testcase;

 int hours;
 string solution; 
 solution.resize(10000);
 for(int i=1; i<=testcase; i++)
 {
  solution = "";

  hours = 0;
  int n;
  fin >> n;

  for(int j=1; j<=n; j++)
  {
   int temp;
   fin >> temp;
   A.push_back(temp);
  }

  sort(A.begin(), A.end());
  //saram 에 대한 처리가 들어감
  while(A.empty() == false)
  {
   if(A.size() == 1)
   {
    vector<int>::iterator b = A.begin();
    int _A = *b;

    B.insert(B.begin(), A.begin(), A.end());
    A.clear();

    char buf[256];
    sprintf(buf, "%d\n", _A);
    solution += buf;
    hours += _A;
   }
   else if(A.size() == 2)
   {
    vector<int>::iterator b = A.begin();
    int _A = *b;
    b++;
    int _B = *b;

    B.insert(B.begin(), A.begin(), A.end());
    A.clear();
    char buf[256];
    sprintf(buf, "%d %d\n", _A, _B);
    solution += buf;
    hours += _B;
   }
   else if(A.size() == 3)
   {
    vector<int>::iterator b = A.begin();
    int _A = *b;
    b++;
    int _B = *b;
    b++;
    int _C = *b;


    B.insert(B.begin(), A.begin(), A.end());
    A.clear();
    char buf[256];

    sprintf(buf, "%d %d\n", _A, _B);
    solution += buf;

    sprintf(buf, "%d\n", _A);
    solution += buf;

    sprintf(buf, "%d %d\n", _A, _C);
    solution += buf;
    hours += _A + _B + _C;
   }
   else if(A.size() >= 4)
   {
    vector<int>::iterator b = A.begin();
    vector<int>::reverse_iterator rb = A.rbegin();
    int _A = *b;
    b++;
    int _B = *b;
    int _Z = *rb;
    rb++;
    int _Y = *rb;

    A.erase(find(A.begin(), A.end(), _Y));
    A.erase(find(A.begin(), A.end(), _Z));
    //A.erase(_Y);
    //A.erase(_Z);
    B.push_back(_Y);
    B.push_back(_Z);
    if(_A + 2*_B + _Z <= 2*_A + _Y + _Z)
    {    
     char buf[256];
     sprintf(buf, "%d %d\n", _A, _B);
     solution += buf;
     sprintf(buf, "%d\n", _A);
     solution += buf;
     sprintf(buf, "%d %d\n", _Y, _Z);
     solution += buf;
     sprintf(buf, "%d\n", _B);
     solution += buf;

     hours += _A + 2*_B + _Z;
    }
    else
    {
     char buf[256];
     sprintf(buf, "%d %d\n", _A, _Z);
     solution += buf;
     sprintf(buf, "%d\n", _A);
     solution += buf;
     sprintf(buf, "%d %d\n", _A, _Y);
     solution += buf;
     sprintf(buf, "%d\n", _A);
     solution += buf;
     hours += 2*_A + _Y + _Z;
    }
   }
   sort(A.begin(), A.end());
   sort(B.begin(), B.end());
  }
  cout << hours <<endl << solution;
  if(testcase  != i)
   cout << endl;
 }

 return 0;
}

 


'컴퓨터 이야기 > C++' 카테고리의 다른 글

부분집합  (0) 2011.01.07
soccer UVA  (0) 2011.01.07
Vito's Family  (0) 2011.01.02
Erdos Numbers  (0) 2011.01.01
MS Visual Studio Macro 에서 h 과 cpp 파일간의 이동  (0) 2010.08.19
:

Vito's Family

컴퓨터 이야기/C++ 2011. 1. 2. 15:39
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <limits>
#include <time.h>
#include <set>
#include <cmath>
using namespace std;
//#define mycom
#ifdef mycom
#include <fstream>
ifstream fin("input");
#else
#define fin cin
#endif

using namespace std;
int main()
{
 int casenumber;
 fin >> casenumber;

 for(int i=1; i<=casenumber; i++)
 {
  int headnumber;
  fin >> headnumber;
  vector<int> s;
  for(int j=1; j<=headnumber; j++)
  {
   int temp;
   fin >> temp;
   s.push_back(temp);
  }
  
  int nmin = numeric_limits<int>::max();
  
  for(vector<int>::iterator iter = s.begin(); iter != s.end(); ++iter)
  {
   int sum = 0;
   for(vector<int>::iterator iter2 = s.begin(); iter2 != s.end(); ++iter2)
   {
    sum += abs(*iter - *iter2);
   }
   nmin = min(sum, nmin);
  }

  cout << nmin << endl;
 }
 return 0;
}


'컴퓨터 이야기 > C++' 카테고리의 다른 글

soccer UVA  (0) 2011.01.07
Bridge  (0) 2011.01.05
Erdos Numbers  (0) 2011.01.01
MS Visual Studio Macro 에서 h 과 cpp 파일간의 이동  (0) 2010.08.19
projecteuler.net : Problem 25  (0) 2010.08.16
:

Erdos Numbers

컴퓨터 이야기/C++ 2011. 1. 1. 16:12
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <limits>
#include <time.h>
using namespace std;
#define mycom
#ifdef mycom
#include <fstream>
ifstream fin("input");
#else
#define fin cin
#endif

struct Node
{
 string vertex;
 Node* adj;
 bool operator==(const Node& n) const
 {
  return (vertex == n.vertex);
 }
 bool operator<(const Node& n) const
 {
  return vertex < n.vertex;
 }
};


vector<Node> graph;


void CreateVertex(const string& v)
{
 Node n;
 n.vertex = v;
 n.adj = 0;
 bool bfind = false;
 if( find(graph.begin(), graph.end(), n) == graph.end() ) // 없
  graph.push_back(n);
}


void link(const string& from, const string& to)
{
 Node s;
 s.vertex = from;
 vector<Node>::iterator fromiter = find(graph.begin(), graph.end(), s);
 Node* p = new Node;
 p->vertex = to;
 p->adj = fromiter->adj;
 fromiter->adj = p;
}


int sina;
int non;
int saram;

 


int mymin = 9999999;
map<string, bool> visit;
void dfs(const string& curnode, int mycount)
{
 //해가 맞는가?
 //아니면
 //모든 경우에 대해 백트
 visit[curnode] = true;
 ///cout << curnode << endl;
 if(curnode == "Erdos, P.")
 {
  if (mycount < mymin)
   mymin = mycount;
 } else
 {
  Node s;
  s.vertex = curnode;
  Node* p = &(*find(graph.begin(), graph.end(), s));
  while(p)
  {   
   if(mymin > mycount )
   {
    if( p->adj && !visit[p->adj->vertex] )
     dfs(p->adj->vertex, mycount + 1);
   }
   p = p->adj;
  }
 }
 visit[curnode] = false;
}


int main()
{

 
 fin >> sina;
 for (int i = 1; i <= sina; i++)
 {
  //memset(graph, 0, sizeof(graph));


  fin >> non >> saram;
  //
  char t;
  while (fin.get(t) && t != '\n')
   ;
  
  for (int j = 1; j <= non; j++)
  {


   char temp[1024];
   fin.getline(temp, 1024);
   int startpos = 0;
   vector<string> v;
   for (int i = 0; i < strlen(temp); i++)
   { // 문자열 파싱.
    if (strncmp(&temp[i], ".,", 2) == 0 || strncmp(&temp[i], ".:", 2) == 0)
    {
     string strtemp;
     strtemp.assign(&temp[startpos], &temp[i + 1]);
     v.push_back(strtemp);


     startpos = i + 3;
    }
   }

   
   //이어주기
   for (int z = 0; z < v.size(); z++)
   {
    for (int z2 = 0; z2 < v.size(); z2++)
    {
     if(z != z2)
     {
      CreateVertex(v[z]);
      CreateVertex(v[z2]);
      link(v[z], v[z2]);
      //link(v[z2], v[z]);
     }
    }
   }
   
  }
  
  //for(map<string, int>::iterator i = dic.begin(); i != dic.end(); i++)
  // cout << i->first << i->second << endl;
  //while (fin.get(t) && t != '\n');
  cout << "Scenario " << i << endl;
  
  char temp[1024];
  for (int j = 1; j <= saram; j++)
  {
   fin.getline(temp, 1024);
   
   mymin = numeric_limits<int>::max();
   clock_t start = clock(); 
   dfs(temp, 0);
   //cout << clock() - start << endl;
   if (mymin == numeric_limits<int>::max())
    cout << temp << " " << "infinity" << endl;
   else
    cout << temp << " " << mymin << endl;
  }
 }


 return 0;
}


'컴퓨터 이야기 > C++' 카테고리의 다른 글

Bridge  (0) 2011.01.05
Vito's Family  (0) 2011.01.02
MS Visual Studio Macro 에서 h 과 cpp 파일간의 이동  (0) 2010.08.19
projecteuler.net : Problem 25  (0) 2010.08.16
API 후킹  (0) 2010.07.19
:

123

카테고리 없음 2010. 12. 31. 00:50
void dfs(int curnode, int mycount)
{
//해가 맞는가?
//아니면
//모든 경우에 대해 백트
visit[curnode] = true;
if(dic["Erdos, P."] == curnode)
{
if(mycount < mymin)
mymin = mycount;
}
else
{
for(map<string, int>::iterator i=dic.begin(); i != dic.end(); i++)
{
//cout << i->second << endl;
if(graph[curnode][i->second] && !visit[i->second])
{
dfs(i->second, mycount+1);
}
}
}
visit[curnode] = false;
}
:

zumdahl 7th 화학 솔루션

카테고리 없음 2010. 10. 24. 11:26
:

물리 8th solution

잡담 2010. 10. 17. 11:40
:

방학 때 까지 인터넷 활동은 잠시 중단...

잡담 2010. 9. 24. 09:24
뭐 급꼴 하면 글 쓸 수도 있지만 잠시 버로우하고 있겠습니다.

'잡담' 카테고리의 다른 글

9학기 테크트리 - 추후 8학기 테크 올림  (0) 2011.02.08
물리 8th solution  (0) 2010.10.17
군대에서는 시간이 잘 안가는 이유  (2) 2010.09.18
리겜 컨트롤러 제작에 들어갑니다.  (1) 2010.09.06
기절ㅋ  (0) 2010.09.01
: