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

C++빌더 Q&A
C++Builder Programming Q&A
[70342] Re:알고리즘써서 replace 하는 과제좀 도와주세요 ㅠ
차돌이 [scd8510] 3596 읽음    2013-11-20 09:28
Stringreplace 함수를 사용하세요.
뉴비 님이 쓰신 글 :
:



:
:  1 #include<iostream>
:   2 #include<string>
:   3 #include<fstream>
:   4 #include<algorithm>
:   5 #include<time.h>
:   6 using namespace std;
:   7
:   8 string replace(string s)
:   9 {
:  10 replace(s.begin(),s.end(),0,0);
:  11 return s;
:  12 }
:  13
:  14 int main()
:  15 {
:  16   string* sp;
:  17   int x;
:  18
:  19
:  20   ifstream inf("stage3.txt");
:  21   ofstream outf("Decrypted.txt");
:  22   inf >> x;
:  23   inf.ignore();
:  24   sp=new string[x];
:  25   time_t rawtime;
:  26   struct tm* timeinfo;
:  27   time(&rawtime);
:  28   timeinfo=localtime(&rawtime);
:  29
:  30   for(int i=0; i<x; ++i)
:  31   {
:  32     string s;
:  33     getline(inf,s);
:  34     sp[i]=replace(s);
:  35
:  36     if(sp[i].find("Decrypt stage 1 complete")!=string::npos)
:  37       sp[i]="Decrypted by Y";
:  38     if(sp[i].find("Decrypt stage 2 complete")!=string::npos)
:  39       sp[i]=asctime(timeinfo);
:  40
:  41     cout<< sp[i] <<endl;
:  42   }
:  43
:  44    for(int i=0; i<x; ++i)
:  45   {
:  46     outf<< sp[i]<<endl;
:  47   }
:  48   sp=NULL;
:  49   delete []sp;
:  50 }
: 대충 소스는 짜봤는데요,
: Replace “barn” with “Galactica”
:
: Replace “toaster” with “Cylon”
:
: Replace “juice” with “fuel”
:
: Replace “wagon” with “viper”
:
: Replace “stage 1” with the current time
:
: Replace “stage 2” with “FRAKKEN”
: 각각 이 단어들을 replace해야 하는데 어떻게 하는지 모르겠어요
: 루프안에다가 if 로 쓰니까 문장 전체가 교체되버려서 하나씩만 교체 하려면 어떻게 하는지 모르겠어요 도와주세요 ㅠ
:
:

+ -

관련 글 리스트
70341 알고리즘써서 replace 하는 과제좀 도와주세요 ㅠ 뉴비 13709 2013/11/19
70342     Re:알고리즘써서 replace 하는 과제좀 도와주세요 ㅠ 차돌이 3596 2013/11/20
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.