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문 끔 는방 .?
보 ~ 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
Goto Statements Considered Harmful
GotoConsideredHarmful -
- ~ 대~ ~ - 민
- ...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
본 . 대 동 문 메릭 모 돌 -_-;;;
*/











-