ÇÁ·Î±×·¡¹Ö

 3198, 1/160 ȸ¿ø°¡ÀÔ  ·Î±×ÀΠ 
   jjong1986
   c,c++ Áú¹®ÀÔ´Ï´Ù. µ¿ÀûÇÒ´ç °ü·Ã...

http://www.hackerschool.org/HS_Boards/zboard.php?AllArticle=true&no=2916 [º¹»ç]


¹®Á¦°¡


      ´Ü¾îÀÇ °¹¼öÀÔ·Â : 3
      ´Ü¾î1:television
      ´Ü¾î2:hi
      ´Ü¾î3:welcome

      (ÀԷ´ܾî)television-hi-welcome

ÀÌ·¸°Ô Ãâ·ÂµÇµµ·Ï Â¥´Â °ÍÀä
Á¦°¡ µ¿ÀûÇÒ´çÀ» À߸ô¶ó¼­¿ä Á¦°¡  Äڵ尡 Àִµ¥ Á»ºÁÁÖ¼¼¿ä ¤Ð¤Ð
/*  
//À̰æ¿ì¿¡´Â ¹®ÀÚÇϳª¾¿ ¹Û¿¡ ÀÔ·ÂÀÌ¾ÈµÇ¿ä ¤Ð¤Ð
//¹®ÀÚ¿­ ÀԷ¹æ¹ý¸¸ ¾Ë¸éµÉ°Í°°Àºµ¥ ¤Ð¤Ð..
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <string.h>
int main()
{
        int n,i;
        char *ch;
        scanf("%d",&n);
        ch = (char*)malloc(sizeof(char*)*n);
        for(i=0;i<n;i++)
        {
                printf("´Ü¾î%d:",i+1);
                cin>>ch[i];
        }
        for(i=0;i<n;i++)
        {
                cout<<ch[i]<<endl;
        }
        free(ch);
        return 0;
}
*/

  Hit : 3975     Date : 2011/03/17 02:41



    
º°ºûÀ»´ã¾Æ ÀÏ´Ü È®½ÇÈ÷ ÇÏ°í ½ÍÀº°Ô¿ä...
ÀÌ°Ô C¾ð¾îÀΰ¡¿ä C++Àΰ¡¿ä? ¤·¤µ¤·
cinÀ̳ª coutÀÌ ÀÖ´Â°É º¸¸é C++Àε¥.... mallocÀº C¾ð¾î¼­ ¾²´Â °Å°Åµç¿ä
C++À» °øºÎÇϽŴٸé mallocº¸´Ù´Â new¿Í delete¸¦ »ç¿ëÇÏ½Ã´Â°Ô ´õ ÆíÇÏ°í ½±°Ô ÇÒ ¼ö ÀÖ½À´Ï´Ù.
2011/03/17  
jjong1986 ¾Æ¾Æ µÑ´Ù °øºÎÇØ¼­ Á» ¼¯¾î¼­ ÇØº¸¾Ò¾î¿ä ¤Ð¤Ð Á¦°¡ ½Ç·ÂÀÌ º°·Î ¾ø¾î¼­ È¿À²º¸´Ù´Â Áö±Ý ÇÁ·Î±×·¥ÀÌ °¡µ¿µÇ´Â°É Áß¿ä½ÃÇϰí À־¿ä ¤Ð¤Ð 2011/03/17  
rainroad87 C¾ð¾î
------------------------------------------------------------------------
#include "stdafx.h"
#include <stdio.h>
#include <malloc.h>
#include <string.h>

#define MAX_WORD_LEN 80
#define MAX_WORD_COUNT 10

int main()
{
int nWordCount = 0;
int i=0;
char szTotalWord[MAX_WORD_LEN*MAX_WORD_COUNT] = {0,};

printf("´Ü¾îÀÇ °¹¼ö ÀÔ·Â : ");
scanf("%d",&nWordCount);

if(nWordCount > MAX_WORD_COUNT)
{
return -1;
}

for(i=0;i<nWordCount;i++)
{
char *szWord = (char*)malloc(sizeof(char)*MAX_WORD_LEN);

printf("´Ü¾î%d : ",i+1);
scanf("%s",szWord);

if(i != nWordCount-1)
{
sprintf(szWord,"%s-",szWord);
}

strcat(szTotalWord,szWord);

free(szWord);
}
printf("ÀԷ´ܾî : %s\n",szTotalWord);
}
2011/03/17  
rainroad87 C++¾ð¾î
------------------------------------------------------------------------
#include "stdafx.h"
#include <iostream>
using namespace std;

#define MAX_WORD_LEN 80
#define MAX_WORD_COUNT 10

class MergeWord
{
public:
int m_WordCout;
char m_szTotalWord[MAX_WORD_LEN*MAX_WORD_COUNT];
bool m_bErrorCount;

public:
MergeWord()
{
m_WordCout = 0;
memset(m_szTotalWord,0,sizeof(m_szTotalWord));
m_bErrorCount = true;
}
bool Run()
{
if(!m_bErrorCount)
{
return false;
}
for(int i=0;i<GetWordCount();i++)
{
char Word[MAX_WORD_LEN] = {0,};
cout << "´Ü¾î" << i+1 << " : ";
cin >> Word;
SetWord(i,Word);
}
return true;
}

void SetWordCount(int WordCount)
{
if(WordCount > MAX_WORD_COUNT)
{
m_bErrorCount = false;
}
m_WordCout = WordCount;
}
void ShowWords()
{
if(m_bErrorCount)
{
cout << "ÀԷ´ܾî : " << m_szTotalWord << endl;
}
}

private:
void SetWord(int nCount,char* Word)
{
char *szWord = new char[MAX_WORD_LEN];
strcpy(szWord,Word);

if(nCount != GetWordCount()-1)
{
sprintf(szWord,"%s-",szWord);
}

strcat(m_szTotalWord,szWord);

delete[] szWord;
}

int GetWordCount()
{
return m_WordCout;
}
};

int main()
{
MergeWord Word;
int nWordCount = 0;

cout << "´Ü¾îÀÇ °¹¼öÀÔ·Â : ";
cin >> nWordCount;
Word.SetWordCount(nWordCount);
if(!Word.Run())
{
return -1;
}
Word.ShowWords();
return 0;
}
2011/03/17  
rainroad87 Á¦ÀÏ ½¬¿î ¹æ¹ý
-------------------------------------------------------
#include "stdafx.h"
#include <stdio.h>

void main()
{
printf("´Ü¾îÀÇ °¹¼öÀÔ·Â : 3\n");
printf("´Ü¾î1:television\n");
printf("´Ü¾î2:hi\n");
printf("´Ü¾î3:welcome");
printf("\n");
printf("(ÀԷ´ܾî)television-hi-welcome\n");
}
2011/03/17