U E D R , A S I H C RSS

빵페이지/숫자야구

1.



DeleteMe 복되 료 부 다. 라는 복되는 . ~cpp 구/ 것 같다.--NeoCoin


  • ~ 는데 게 또 -_ㅜ -
    • 보면 만 결고 - 민
  • 4로 만든 는데 되나?? X같;; -
  • 그리고 rand() 만 면 똑같 만 된다고.. 뭐 다른것 되던데.. -
    • ctime 를 include 고 srane(time(0)); 면 바뀔~ - 민


2.

~cpp 
#include <iostream>
#include <stdlib.h> 
#include <time.h> 
using namespace std;
 int main()
{
	
	int num[3];
	while(num[0]==num[1] || num[1]==num[2] || num[0]==num[2])
	{
	srand(time(NULL)); 
   for(int i=0; i<3; i++)
      num[i] = rand()%9 +1; 
    }
	cout <<"  : " << num[0] << num[1] << num[2] << "\n";
	int ch; 
	while(ch) // X  
	{cout <<"력 : ";
	cin >> ch;
	
	
	int person[3];
 	int bcount=0;
	int scount=0;
	person[0] = ch/100;
	person[1] = (ch%100)/10;
	person[2] = (ch%10);

		for(int i=0;i<3;i++)
		{
			for(int j=0;j<3;j++)
			{
			if(num[i]==person[j])
				{
				if(i==j)
					scount++;
				else
					bcount++;
				}
			}
		}

		 if(scount==0 && bcount==0)
			cout << "력 : OUT\n";
		else if(scount==0 && bcount!=0)
			cout << "력 : "<< bcount << "볼\n";
		else if(bcount==0 && scount!=0)
		{	cout << "력 : " << scount << "\n";
			if(scount==3)
				break;
		}
		else 
			cout << "력 : "<< scount << " " << bcount << "볼\n"; 
	}
		cout << "로그램 .\n";
		return 0;
	
}
.. -_-+
다보다~ while문 고 깔끔는방법 까.?

  • ,, ~ ㅋㅋ - 민
  • 면 매 모드 돌 -_-;;; -
    • 룬것.ㅋㅋ


3.

~cpp 
// 베볼 게다.  기 게로 4 를 9  다.

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

int main()
{
	int rand_num[3]; //난 될 변다.
	int i, j, k, num;   //i,j,k 는 , num   다.
	int player_num[3];  //로 나 rand_num과 게 만듭다.
	int ext,extra;    //다.
	int strike, ball; //  다.
 
	srand(time(NULL));
 
	for(i=0;i<3;i++){
		rand_num[i] = rand()%10;   // 다.
		if (i == 1 && rand_num[i] == rand_num[0]) 
			i--;
		else if (i == 2 && (rand_num[i] == rand_num[0] || rand_num[i] == rand_num[1])) 
			i--;
	}          // if 문  4가 모두 다르게 배되게 다.
 
	for (i=0;i<9;i++){   //게 
		cout << "3(가 겹 ) : " ;
		cin >> num;
		ext = num;
  
		if (num < 100 || num > 999) {
			cout << "\a 다. 다  . \n";
			i--;
		}
		else{
			for (j=2;j>=0;j--){//를 배로 바꾸는 문
				player_num[j] = ext%10;
				ext = ext/10;
			}
			for(j=0;j<2;j++){  //각
				extra = 1;
				for(k=j+1;k<3;k++){
					if (player_num[j] == player_num[k]) {
						cout << "\a 다. 다  . \n";
						i--;
						extra = 0;
						break;
					}
					if (extra == 0) break;
				}
				if (extra == 0) break;
			}   // 각문 끝
		}    // else 문 끝
                  	if (extra == 0) continue;

		strike = 0;
		ball = 0;

		if (extra == 1) {
			for(j=0;j<3;j++){  
				for(k=0;k<3;k++){
					if (rand_num[j] == player_num[k] && j==k) strike++;
					if (rand_num[j] == player_num[k] && j!=k) ball++;
				}
			}
		}
		if (strike == 0 && ball == 0) cout << "다.\n";
		else cout << strike << ", " << ball << "볼 다.\n";
		if (strike == 3) {
			cout << "를 맞다.!!\n";
			break;
		}
		if (i==8 && strike!=3) cout << "9  다.\n";
	}     // 게 끝
	return 0;
}
보고 놀라들 말길 -_-;;; -


  • .. 그리고 다 깨는데..
    떻게 모르겠 ㅜㅜ -

4.

~cpp 
#include<iostream> //  ^^
#include<ctime>
using namespace std;
int main()
{
	int num[3];
	int yagu[3];
	int a;
	cout<<":";
	srand(time(NULL));
	do
	{
	for(int i=0;i<3;i++)
	num[i]=rand()%9+1;
	}while(!(num[0]!=num[1] && num[1]!=num[2] && num[2]!=num[0]));
		cout<<num[0]<<num[1]<<num[2];
up :
	cout<<"\n력:"; 
	cin>>a;
	if(a<1000 && a>99)
		{
			yagu[0]=a/100;
			yagu[1]=(a-yagu[0]*100)/10;
			yagu[2]=(a-yagu[0]*100-yagu[1]*10);
		}
	else
			cout<<":";
	
	int strike=0;
	int ball=0;
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<3;j++)
		{
			if(yagu[i]==num[j])
			{
				if(i==j)
					strike++;
				if(i!=j)
					ball++;
			}
		}
	}
	if(strike!=0 && ball==0)
		if(strike==3)
			cout<<strike<<"! 료";
		else
		{cout<<strike<<"";
		goto up;
		}
	else if(strike==0 && ball!=0)
	{
		cout<<ball<<"볼";
		goto up;
	}
	else if(strike!=0 && ball!=0)
	{
		cout<<strike<<""<<ball<<"볼";
		goto up;
	}
	else
	{
		cout<<"out";
		goto up;
	}
	return 0;
}
  • goto문 각나 는데 ... ... 빠가 goto문 는 게 다고 것 같데.. ㅡㅜ 떻게 ?? 로그램 바르게 돌가는 게 맞는 미루고 못 렸는데 .. 린 것 길.... -
    - 무든 100% 고 100% 나 다. dijkstra 가 goto 를 말라고 달리 는 많 논문 다. 냐? 냐?라 그 결론 기까다. SeeAlso NotToolsButConcepts Seminar: Goto Statements Considered Harmful 구글 검결과 Wiki:GotoConsideredHarmful -
    - 드를 보 블로 cin . cin c++ ostream 다. 드를 게 그 미가 달될 다. -
    • !빠~ thank you~^^ -
  • ~ 대단~ ~ - 민
  • ...goto...보는다 =ㅅ= -
  • goto 문 2003 4 라가 goto (?)를 라는 기를 보. 2003 GotoConsideredHarmful 된 기다. Dijkstra 각들 다. --무개
  • 문득 다 go to 보게 되. 방법데.. -

5. 구게 v1.3

~cpp 
#include <iostream.h>
#include <stdlib.h>
#include <ctime>
void game();
void new_game();


void main()
{
        cout << "┌──────────────────────────┐\n" 
                "│                                                    │\n" 
                "│                                                    │\n" 
                "│                        구                    │\n" 
                "│                                                    │\n" 
                "│                      게    ver 1.3               │\n" 
                "│                                                    │\n" 
                "│                                                    │\n" 
                "│                                                    │\n" 
                "│                                  Made by 균    │\n" 
                "│                                                    │\n" 
                "└──────────────────────────┘\n";//  면	

         cout << "\n";

	game(); // 게 
}

void game()
{
	char random[4]; // 로 만들 는 배
	char space[64]; // 는 배
	int strike = 0; //   
	int ball = 0; // 볼  
	srand(time(NULL));
	
	for (int i = 0; i < 4; i++)	
	{	
		random[i] = '0' + rand() % 9 + 1;
        for (int j = 0; j < i; j++)
			if (random[i] == random[j])
			{
				i--;
				break;
			}
	} // 랜덤게 4다
	
	
	/*cout << random[0] << random[1] << random[2] << random[3] << endl;*/ // 대략 답 -_-;;;


	cout << "랜덤게 4를 만들다. 맞 *^^* (료 : Q)\n\n";
	
	int success = 0; // 대로    (0 = , 1 = 공)

	while (success == 0)
	{	
		cout << " : ";
		cin.getline(space, 64);
		success = 1;

		if ((space[0] == 'q' || space[0] == 'Q') && space[1] == '\0') 
		{
			cout << "Bye!!\n";
			exit(0);
		} //  'Q'를 료
		
		for (i = 0; i < 4; i++)
		{	
			if (space[i] < '1' || space[i] > '9') 
			{
				success = 0;
                break;
			}
		} // 1~9 대로 력되  
        if (space[4] != '\0')
			success = 0; // 4리가  력되 
		for (i = 0; i < 3; i++)
			for (int h = i + 1; h < 4; h++)
				if (space[i] == space[h])
				{	
					success = 0;
					break;
				} //  
		if (success == 0)
			continue; //   1개라 리면 다 력

		//  대로 ...
		
		for (int j = 0; j < 4; j++)
		{
			if (space[j] == random[j])
				strike++; //  
			for (int k = 0; k < 4; k++)
				if (j != k && space[j] == random[k])
					ball++; // 볼 
				else 
					continue;
				
		}
			
		if (strike == 0 && ball == 0)
		{
			cout << "결과 : ";
			cout << "OUT!!";	// , 볼 는 겨 'OUT' 력		
		}
		else if (strike == 4)
			new_game(); //  new_game동
		else
		{
			cout << "결과 : ";
			cout << strike << "S" << "  " << ball << "B";
		} //  결과 력
		
		cout << endl;
		
		strike = 0;
		ball = 0; 
		success = 0; // success를 0 while문 다 
	}
}


void new_game() // 게  기로 동
{	
	cout << "맞다. 또 까? (Y/N) : ";
	char ch;
	cin >> ch;
	
	while (ch != 'y' || ch != 'Y' || ch != 'n' || ch != 'N')
	{
		if (ch == 'y' || ch == 'Y')
		{
			while (cin.get() != '\n')
				continue; // y를 기는 개 
			game();
			break;
		}
		else if (ch == 'n' || ch == 'N')
		{	
			cout << "Bye!!\n";
			exit(0); // 게 료
		}
		else
		{
			cout << "맞다. 또 까? (Y/N) : ";
			cin >> ch; 
		}
	}
}


/*
Ver 1.3 Update
게  료기능 가

Ver 1.2 Update
개 기 (무 ㅜㅜ)

Ver 1.1 Update
3 4로 변경.  .

Ver 1.0
기본  . 게 대로 구동되나    모드 돌 -_-;;;
*/

...무 ㅜㅜ
그래 뿌듯.
그리고...
대!!!!!!!!!!
님.
기본 는데,
모드 .

P.S. ...리가 보기 군 (럭) C++ ~_~
Digi-VM

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:38
Processing time 0.0222 sec