Turbo-C
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
터보-C 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
Lua 게시판
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C/C++ Q/A
[2583] Re:저번 답변 감사합니다..근데..
실업자 [origin] 991 읽음    2003-05-08 01:33
이게 행맨인가요?
행맨이란 말을 처음 들어봐서 그냥 요구사항에 따라 코딩해봤습니다.

#include<stdio.h>
#include<conio.h>
#include<string.h>

int MatchChar(const char *pWord,char ch,int *matched);

int main(void)
{
const int MaxTrial=15;
const char *const pWord="concatenation";
const int wordLen=strlen(pWord);
int matchedCount=0;
int matchedIndice[16]={0,};
char ch;
int i ,idx;
const int y=wherey();

for(i=1 ;i<=wordLen ;i=i+1){
  putchar('_');
}

printf("\n     : Input a Character. ");

for(i=1 ;i<=MaxTrial ;i=i+1){
  gotoxy(1,y+1);
  printf("%2i/%2i",i,MaxTrial);
  gotoxy(i+26,y+1);
  ch=getche();
  if((idx=MatchChar(pWord,ch,matchedIndice))>=0){
   matchedCount=matchedCount+1;
   gotoxy(idx+1,y);
   putchar(ch);
   if(matchedCount==wordLen) break;
  }else if(wordLen-matchedCount>MaxTrial-i){
   break;
  }
}

gotoxy(1,y+2);
if(matchedCount==wordLen) {
  printf("You Win!");
}else{
  printf("Failed!");
}

getch();
return 0;
}


int MatchChar(const char *pWord,char ch,int *matched)
{
const char *p=pWord;
int index;
if(!pWord || !matched) return -1;
while(1){
  p=strchr(p,ch);
  if(!p) return -1;
  index=p-pWord;
  if(matched[index]==0){
    matched[index]=1;
    return index;
  }else{
   p=p+1;
  }
}
}

ㅠ_ㅠ 님이 쓰신 글 :
:  그냥 단순한 씨 언어만으로 짠프로그램은 없을까요..
:
: 아직은 제가 초보라서 뭐가 뭔지 봐도 모르겠네요..ㅠ_ㅠ
:
: 초보자에 맞는게 필요한데..흑흑..
:
: 문제 다시 올려드릴게요..
:
: 행맨하는 프로그램을 작성하는건데 이 게임에서는 하나의 단어를 숨겨두고서 단지 그 단어의 길이만큼 밑줄을 화면에 표시한후, 사용자는 영문자를 입력함으로써 그 단어를 맞춰야 한다. 사용자가 하나의 문자를 입력할때마다, 숨겨진 단어에 그 문자가 포함되어 있는지를 확인한다. 만약 포함되어 있으면, 그 문자를 화면에 보여준다. 그 단어를 완전히 알아 맞출때까지 입력된 문자들의 수를 센다. 프로그램을 간단히 하기 위해 15번 이하의 시행에서 단어를 알아맞추면 이긴것으로 간주하여라.. 숨겨진 단어로 concatenation을 사용하여라.. 행맨그림은 문자로 만들라는데 어떻게 하는질 모르겠어요..ㅠ_ㅠ
:
: 고수님들 제발 부탁드려요..ㅠ_ㅠ

+ -

관련 글 리스트
2582 저번 답변 감사합니다..근데.. ㅠ_ㅠ 933 2003/05/07
4045     Re:저번 답변 감사합니다..근데.. 김백일.cedar 977 2003/05/08
4044     Re:저번 답변 감사합니다..근데.. 임문환.실업자 923 2003/05/08
2583     Re:저번 답변 감사합니다..근데.. 실업자 991 2003/05/08
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.