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 기본 . 게 대로 구동되나 문 력 메릭 모드 돌 -_-;;; */