'Code/Algorism'에 해당되는 글 8건

  1. 2011.09.03 [ALGORISM]poj 1166
  2. 2011.09.03 [ALGORISM]poj 1218
  3. 2011.09.03 [ALGORISM]poj 1298
  4. 2011.09.03 [ALGORISM]poj 2853
  5. 2011.09.03 [ALGORISM]poj 1077
  6. 2011.09.03 [ALGORISM]poj 1163
  7. 2011.09.03 [ALGORISM]poj 1003
  8. 2011.09.03 [ALGORISM] poj 3085
2011. 9. 3. 14:48

//poj 1166
//2011 07 04
//daun
#include <iostream>
using namespace std;

void swap(int *a,int *b)
{
 int temp = *a;
 *a = *b;
 *b = temp;
}

int main()
{
 int arr[3][3]={0};
 int i = 0;
 int end = 0;
 int result[27] ={0};
 int count = 0;

 for(int a = 0 ; a< 3 ; a++)
  for(int b = 0 ; b< 3; b++)
   cin>>arr[a][b];
 while(end!=9)
 {
  end = 0;
  if(arr[0][1]* arr[1][0] *arr[1][1]* arr[1][2] * arr[2][1] )
  {
   arr[0][1]++;
   arr[1][0]++;
   arr[1][1]++;
   arr[1][2]++;
   arr[2][1]++;
   result[count] = 5;
  }
  else
  {
   if(!arr[i][1])
   {
    if(!arr[1][i])
     i++;
   }
   else if(!arr[i][0])
   {
    arr[i][1]++;
    arr[i][2]++;
    arr[i+1][1]++;
    arr[i+1][2]++;
    if(i == 0)
     result[count] = 3;
    if(i == 1)
     result[count] = 9;
   }
   else if(!arr[i][2])
   {
    arr[i][0]++;
    arr[i][1]++;
    arr[i+1][0]++;
    arr[i+1][1]++;
    if(i == 0)
     result[count] = 1;
    if(i == 1)
     result[count] = 7;
   }
   if(arr[i][0]*arr[i][1]* arr[i][2])
   {
    arr[i][0]++;
    arr[i][1]++;
    arr[i][2]++;
    if(i == 0)
     result[count] = 2;
    else
     result[count] = 8;
   }

   if(arr[0][i]* arr[1][i] * arr[2][i] )
   {
    arr[0][i]++;
    arr[1][i]++;
    arr[2][i]++;
    if(i == 0)
     result[count] = 4;
    else
     result[count] = 6;
   }
  } 

  for(int a = 0; a < 3 ; a++)
   for(int b= 0 ; b< 3; b++)
   {
    if(arr[a][b] >=4)
     arr[a][b] = arr[a][b]%4;
    if(arr[a][b] == 0)
     end++;
   }
   if(result[count])
  count++;

 }
 
 for(int a = 1; a<count; a++)
  for(int b = a; b<count; b++)
  if(result[b]<result[b-1])
  {
   int temp = result[b-1];
   result[b-1] = result[b];
   result[b]= temp;
  }

 for(int a = 0 ; a < count; a++)
  cout << result[a] << "\t";

 return 0;
}

'Code > Algorism' 카테고리의 다른 글

[ALGORISM]poj 1218  (0) 2011.09.03
[ALGORISM]poj 1298  (0) 2011.09.03
[ALGORISM]poj 2853  (0) 2011.09.03
[ALGORISM]poj 1077  (0) 2011.09.03
[ALGORISM]poj 1163  (0) 2011.09.03
Posted by I_co
2011. 9. 3. 14:48

//2011 07 05
//poj 1218
//daun
#include <iostream>
using namespace std;

int main()
{
 int cell=0;
 int count = 0;
 int number = 0;
 cin>>count;
 for(;count>0;count--)
 {
  number = 0;
 bool arr[101] = {0}; // 0이 열린거 1이 닫힌거

  cin >> cell;

  for(int i = 1 ; i <=cell; i++)
  {
   for(int a = 1 ; a <=cell ; a++)
   {
    if(a%i == 0)
    {
     if(!arr[a])
      arr[a] = 1;
     else if(arr[a])
      arr[a] = 0;
    }
   }
  }

  for(int i = 1 ; i <=cell; i++)
   if(arr[i])
    number ++;

  cout << number<<endl;
 }
 return 0;
}

'Code > Algorism' 카테고리의 다른 글

[ALGORISM]poj 1166  (0) 2011.09.03
[ALGORISM]poj 1298  (0) 2011.09.03
[ALGORISM]poj 2853  (0) 2011.09.03
[ALGORISM]poj 1077  (0) 2011.09.03
[ALGORISM]poj 1163  (0) 2011.09.03
Posted by I_co
2011. 9. 3. 14:47

//2011 07 02
//POJ 1298
//The Hardest Problem Ever


//1~200자의 문자를 받음 옆으로 5칸씩 -> 아스키코드 이용하여 출력
//int 배열로 받고, 끝나는거 확인하구 입력은... 아 끝나는게 문제구나

#include <iostream>
#include <string>
using namespace std;

int main()
{
 string strStart, strEnd;
 string strIn[100];
 int i = 0;
 getline(cin,strStart) ;

 while(strStart != "ENDOFINPUT")
 {
  getline(cin,strIn[i]);
  for(int a = 0 ; a < strIn[i].length()  ; a++)
  {
   if(strIn[i][a] >= 65 && strIn[i][a] <=90)
   {
    strIn[i][a] -= 5;
    if(strIn[i][a] < 65 && strIn[i][a] >=60)
     strIn[i][a] += 26;
   }
  }
  getline(cin,strEnd);
  i++;
  getline(cin,strStart) ;
 }


 for(int a= 0 ; a <i ; a++)
 {
  cout << strIn[a];
  cout << endl;
 }
 system("pause");
 return 0;
}

'Code > Algorism' 카테고리의 다른 글

[ALGORISM]poj 1166  (0) 2011.09.03
[ALGORISM]poj 1218  (0) 2011.09.03
[ALGORISM]poj 2853  (0) 2011.09.03
[ALGORISM]poj 1077  (0) 2011.09.03
[ALGORISM]poj 1163  (0) 2011.09.03
Posted by I_co
2011. 9. 3. 14:47


//2011 07 05
//poj 2853
//daun
#include <iostream>
using namespace std;

int main()
{
 int count = 0;
 int number = 0;
 int answer = 0;
 int i = 0;
 int sum = 0;
 cin >> count;
 while(i!=count)
 {
  cin >> i;
  sum = 0;
  answer = 0;
  cin >> number;
  for(int a = number; a> 0 ; a--)
  {
   sum = a;
   for(int b = a -1; b > 0 ; b--)
   {
    sum+=b;
    if(sum ==  number)
     answer++;
   }
  }
  cout <<i<<" " << answer << endl;
 }
 return 0;
}

'Code > Algorism' 카테고리의 다른 글

[ALGORISM]poj 1218  (0) 2011.09.03
[ALGORISM]poj 1298  (0) 2011.09.03
[ALGORISM]poj 1077  (0) 2011.09.03
[ALGORISM]poj 1163  (0) 2011.09.03
[ALGORISM]poj 1003  (0) 2011.09.03
Posted by I_co
2011. 9. 3. 14:46


//http://poj.org/problem?id=1077
//Eight
//daun

#include <iostream>
#include <conio.h>
#include <winsock2.h>
#include <time.h>
#include <stdio.h>

using namespace std;

enum {BLACK,D_BLUE,D_GREEN,D_SKYBLUE,D_RED,D_VIOLET,D_YELLOW,GRAY,D_GRAY,BLUE,GREEN,SKYBLUE,RED,VIOLET,YELLOW,WHITE,};


void exchange(int *pa, int *pb);
void show(int[][4]);
void SetColor(int backcolor, int fontcolor);
int answer(int arr[][4]);
void start(int *pa, int *pb, int arr[][4]);

int main()
{
 srand(time(NULL));

 system("color F0");
 char type;
 int arr[4][4] = {0};
 int x =0, y=0 ;
 
 start(&x,&y,arr);


 while(1)
 {
  SetColor(WHITE,VIOLET);
  cout <<"\n\n UP : U or u, DOWN : J or j, RIGHT : K or k, LEFT : H or h"<<endl;
  cout <<"\nIf you want to quit, Press the Z or z \n\n"<<endl;
  show(arr);
  switch(type=getch())
  {
  case 'U':
  case 'u':
   if((x-1)>=0)
    exchange(&arr[x][y],&arr[x--][y]);
   else
   {
    SetColor(WHITE,RED);
    cout <<"\nCan't move"<<endl;
   }
   break;
  case 'J':
  case 'j':
   if((x+1)<=3)
    exchange(&arr[x][y],&arr[x++][y]);
   else
   {
    SetColor(WHITE,RED);
    cout<<"\nCan't move"<<endl;
   }
   break;
   case 'K':
   case 'k':
   if((y+1)<=3)
    exchange(&arr[x][y],&arr[x][y++]);
   else
   {
    SetColor(WHITE,RED);
    cout<<"\nCan't move"<<endl;
   }
   break;
  case 'H':
  case 'h':
   if((y-1)>=0)
    exchange(&arr[x][y],&arr[x][y--]);
   else
   {
    SetColor(WHITE,RED);
    cout<<"\nCan't move"<<endl;
   }
   break;
  case 'z':
  case 'Z':
   return 0;
  default:
   SetColor(WHITE,RED);
   cout<<"\nYou press wrong key"<<endl;
  }
  if(answer(arr)==16)
  {
   cout<<"Enswer!!!";
   return 0;
  }
    Sleep(10);
   system("cls");

  
 }


 return 0;

}
void exchange(int *pa, int *pb)
{
 int temp;
 temp = *pa;
 *pa = *pb;
 *pb = temp;
}

void show(int arr[][4])
{
 SetColor(WHITE,BLACK);
 for(int a = 0; a < 4 ; a++)
 {
  for(int b = 0 ; b <4 ; b++)
  {
   if(arr[a][b]==16)
    cout<< 'X' <<"\t";
   else
    cout << arr[a][b] << "\t";
  }
  cout << endl;
 }
}

void SetColor(int backcolor, int fontcolor)
{
 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), backcolor*16+fontcolor);
}

int answer(int arr[][4])
{
 int count=1;
 for(int a = 0 ; a < 4; a++)
  for(int b = 0; b<4 ; b++)
   if(arr[a][b]==count)
    count++;

 return count;

}

void start(int *pa, int *pb, int arr[][4])
{
  for(int i = 1 ; i < 17; i++)
 {
  while(1)
  {
   *pa = rand()%4;
   *pb = rand()%4;

   if(arr[*pa][*pb])
    continue;

   arr[*pa][*pb]=i;
   break;
  }
 }
}

'Code > Algorism' 카테고리의 다른 글

[ALGORISM]poj 1298  (0) 2011.09.03
[ALGORISM]poj 2853  (0) 2011.09.03
[ALGORISM]poj 1163  (0) 2011.09.03
[ALGORISM]poj 1003  (0) 2011.09.03
[ALGORISM] poj 3085  (0) 2011.09.03
Posted by I_co
2011. 9. 3. 14:46


//2011.07.01
//Daun.
//POJ 1163 The Triangle

#include <iostream>
#include <string.h>
#include <stdlib.h>

using namespace std;

int result = 0;

void leftSum(int [][100], int , int ,int); //왼쪽 대각선 아래를 더하는 경우
void rightSum(int [][100], int , int , int); //오른쪽 대각선 아래를 더하는 경우

int main()
{
 int line=1;
 int arr[100][100]= {0};

 memset(arr,-1,sizeof(arr));


 cin >> line;
 //줄수를 입력받음

 for(int a = 0 ; a < line ; a++)
  for(int b = 0 ; b <= a; b++)
   cin>>arr[a][b];
  
 //숫자를 입력 받음

 rightSum(arr,0,0,0);
 leftSum(arr,0,0,0);

 cout << result;

 system("pause");

 return 0;
}

void rightSum(int arr[][100], int a, int b ,int sum)
{
 if(arr[a][b] == -1)
 {
  if( sum > result)
   result = sum;
 }
 else
 {
 sum+=arr[a][b];
 rightSum(arr,a+1,b+1,sum);
 leftSum(arr,a+1,b,sum);
 }
}

void leftSum(int arr[][100], int a , int b,int sum)
{
 if(arr[a][b] == -1)
 {
  if(sum > result)
  result = sum;
 
 }
 
 else
 {
 sum+=arr[a][b];
 leftSum(arr,a+1,b ,sum);
 rightSum(arr,a+1,b+1,sum);
 }
}

'Code > Algorism' 카테고리의 다른 글

[ALGORISM]poj 1298  (0) 2011.09.03
[ALGORISM]poj 2853  (0) 2011.09.03
[ALGORISM]poj 1077  (0) 2011.09.03
[ALGORISM]poj 1003  (0) 2011.09.03
[ALGORISM] poj 3085  (0) 2011.09.03
Posted by I_co
2011. 9. 3. 14:45

// 2011 07 03
// poj 1003
//daun

#include <iostream>
#include <math.h>

using namespace std;


int main()
{
 double sum = 0;

 double length = 0;
 cin >> length;

 while(length != 0)
 {
  sum = 0;
  for(int a = 2 ; ; a++)
  {
   sum += (1/(double)a);

   if(length-sum <0)
   {
    cout << a-1 <<" card(s)"<<endl;
    break;
   }
  }

  cin >> length;
 }
 return 0;
}

'Code > Algorism' 카테고리의 다른 글

[ALGORISM]poj 1298  (0) 2011.09.03
[ALGORISM]poj 2853  (0) 2011.09.03
[ALGORISM]poj 1077  (0) 2011.09.03
[ALGORISM]poj 1163  (0) 2011.09.03
[ALGORISM] poj 3085  (0) 2011.09.03
Posted by I_co
2011. 9. 3. 14:45

//2011 07 06
//poj 3085
//daun
#include <iostream>
using namespace std;

int main()
{
 int QUARTER =0 , DIME = 0, NICKEL = 0, PENNY = 0 ;
 int count = 0;
 int money = 0;
cin >> count;
 for(int i = 1 ; i<=count; i++)
 {
  cin >> money;
  QUARTER = money/25;
  money -= QUARTER * 25;
  DIME = money/10;
  money -= DIME * 10;
  NICKEL = money/5;
  money -= NICKEL * 5;
  PENNY = money/1;
  
  cout << i<<" "<<QUARTER<<" QUARTER(S), "<< DIME <<" DIME(S), "<<NICKEL<<" NICKEL(S), "<<PENNY<<" PENNY(S)"<<endl;


 }

 return 0;
}

'Code > Algorism' 카테고리의 다른 글

[ALGORISM]poj 1298  (0) 2011.09.03
[ALGORISM]poj 2853  (0) 2011.09.03
[ALGORISM]poj 1077  (0) 2011.09.03
[ALGORISM]poj 1163  (0) 2011.09.03
[ALGORISM]poj 1003  (0) 2011.09.03
Posted by I_co