소ê°� ¶
어쩌다가 ì�´ë ‡ê²Œ 길어지게 ë��는지 ëª¨ë¥´ê² ë‹¤.
여튼 처ì�Œ ë¬¸ì œë¥¼ ì ‘í–ˆì�„ 때 ì—°í•„ì�„ ë�„ì �거리지 않았어서 후회가 ìƒ�긴다.
연필� 잡지 않으면 시간� 배로 드는것 같다.
앞으로 실수하지 않게 ë�°ë¸”ìŠ¤ìº í”„ë•Œ ë°°ì› ë“¯ì�´, ê±´ì¶•ì—� 있어서 설계를 작성하는것ì�€ 중요한 것 처럼
프로그래ë°�ì—� 있어서ë�„ 구ìƒ�ê³¼ 설계는 매우 ì¤‘ìš”í•˜ë‹¤ê³ ëŠ�낀다.
여튼 처ì�Œ ë¬¸ì œë¥¼ ì ‘í–ˆì�„ 때 ì—°í•„ì�„ ë�„ì �거리지 않았어서 후회가 ìƒ�긴다.
연필� 잡지 않으면 시간� 배로 드는것 같다.
앞으로 실수하지 않게 ë�°ë¸”ìŠ¤ìº í”„ë•Œ ë°°ì› ë“¯ì�´, ê±´ì¶•ì—� 있어서 설계를 작성하는것ì�€ 중요한 것 처럼
프로그래ë°�ì—� 있어서ë�„ 구ìƒ�ê³¼ 설계는 매우 ì¤‘ìš”í•˜ë‹¤ê³ ëŠ�낀다.
ì•Œê³ ë¦¬ì¦˜ ¶
그냥 ì•Œê³ ë¦¬ì¦˜ì�„ ìƒ�ê°�했다. 어떻게 ë³´ë©´ 복잡한 것 같기ë�„ 하다.ã…¡ã…
His teaching method is very good.
ì�´ë²ˆ 프로그래ë°�ì�˜ ì•Œê³ ë¦¬ì¦˜.
단어ì�˜ 시작ì�„ 중ì �으로 한다.(나는 문ìž�ì—´ ì�´ë�¼ê¸° 보다는 단어 검색 중심으로 ì§ ê²ƒê°™ë‹¤.)
즉, H, t, m, i, v, gê°€ 기ì �ì�´ ë� 수 있다.
문장 �� 단어� 첫 글�와, 찾아볼 단어� 첫글�� ��한가 부터 시작한다.
만약ì—� Hotì�´ë�¼ëŠ” 단어를 ì € 문장ì—�서 찾았ì�„때, ë¨¼ì € H로 시작하는 단어가 있기 때문ì—� His와 비êµ�를 당하게 ë�œë‹¤.
다�� o와 i.. 다르기 때문� found � 0� �어서 찾지 못했�� 알린다.
만약ì—� 첫 글ìž� 부터 ë�™ì�¼í•˜ì§€ 않다면 비êµ�ë�„ 하지 ì•Šê³ ë�„ 찾지못함ì�„ 알린다.
His teaching method is very good.
ì�´ë²ˆ 프로그래ë°�ì�˜ ì•Œê³ ë¦¬ì¦˜.
단어ì�˜ 시작ì�„ 중ì �으로 한다.(나는 문ìž�ì—´ ì�´ë�¼ê¸° 보다는 단어 검색 중심으로 ì§ ê²ƒê°™ë‹¤.)
즉, H, t, m, i, v, gê°€ 기ì �ì�´ ë� 수 있다.
문장 �� 단어� 첫 글�와, 찾아볼 단어� 첫글�� ��한가 부터 시작한다.
만약ì—� Hotì�´ë�¼ëŠ” 단어를 ì € 문장ì—�서 찾았ì�„때, ë¨¼ì € H로 시작하는 단어가 있기 때문ì—� His와 비êµ�를 당하게 ë�œë‹¤.
다�� o와 i.. 다르기 때문� found � 0� �어서 찾지 못했�� 알린다.
만약ì—� 첫 글ìž� 부터 ë�™ì�¼í•˜ì§€ 않다면 비êµ�ë�„ 하지 ì•Šê³ ë�„ 찾지못함ì�„ 알린다.
소스 ¶
~cpp
#include <stdio.h>
void exist_word(char x[40], int exist_str[10]); //x[i]ì—� 문ìž�ì—´ì�˜ ìœ ë¬´
int compare_str(char x[40], char search_str[15], int exist_str[10]); // 문�열 비�
int word_num = 1, search_str_num = 0;
int found = 0; int temp = 0;
void main()
{
char x[40] = "His teaching method is very good.";
char search_str[15];
int exist_str[10]; // exist_str[i]�는 x문�열중 i번째 문�열� 몇번째 문�� 나오나
FILE *fp;
fp = fopen("result.out", "w");
while(1){
word_num = 1; search_str_num = 0; found = 0; temp = 0;
printf("ë��ë‚´ë ¤ë©´ ""EE""ìž…ë ¥\n"); //ì¶œë ¥.
printf("�료 -> %s", x);
printf("\n찾� 문�열 -> ");
scanf("%s", search_str);
fprintf(fp,"ìž�료 -> %s", x); //result.outì—� ì €ìž¥.
fprintf(fp, "\n찾� 문�열 -> ");
fprintf(fp, "%s", search_str);
if(search_str[0] == 'E' && search_str[1] == 'E')
break;
exist_word(x, exist_str);
found = compare_str(x, search_str, exist_str);
switch(found){
case 1:
fprintf(fp, "\nfirst found -> %d\n\n", exist_str[word_num]+1);
break;
case 0:
fprintf(fp, "\nNot found!\n\n");
break;
}
}
fclose(fp);
}
void exist_word(char x[40], int exist_str[10])
{
int num = 2, x_n = 0;
exist_str[1] = 0;
while(x[x_n])
{
if(x[x_n] == ' ')
{
exist_str[num] = x_n + 1; //빈칸 다ì�Œì—� 문ìž�ì—´ì�´ ë‚˜ì˜¨ë‹¤ê³ ê°€ì •.
++num;
}
++x_n;
}
}
int compare_str(char x[40], char search_str[15], int exist_str[10])
{
if(x[exist_str[word_num]] != search_str[search_str_num])
{
++word_num;
if(exist_str[word_num] >= 0)
compare_str(x, search_str, exist_str);
}else{
temp = exist_str[word_num];
while(search_str[search_str_num])
{
if(x[temp] == search_str[search_str_num]){
found = 1;
++temp;
++search_str_num;
}else{
found = 0;
break;
}
}
}
return found;
}
C++로 문ìž� 검색. ¶
~cpp
//cpp1.cpp
#include <iostream>
#include "class.h"
using namespace std;
void main()
{
Search_ch c;
c.input();
c.search();
c.print();
}
~cpp
//cpp2.cpp
#include <iostream>
#include "class.h"
using namespace std;
void Search_ch::input()
{
cin>>str;
cin>>ch;
}
int Search_ch::search()
{
int i, str_len, k;
str_len = strlen(str);
for(i = 0; i <= str_len-1; i++)
{
if(str[i] == ch)
{
k = i;
break;
}else{
k = 0;
}
}
return k;
}
void Search_ch::print()
{
int found_num = search();
if(found_num == 0){
cout << "Not Found!!";
}else if(0 < found_num && found_num < strlen(str)){
cout << "Found!! >>>" <<found_num+1;
}
}
~cpp
//class.h
class Search_ch
{
private:
public:
char str[20];
char ch;
void input();
int search();
void print();
};










