본문 바로가기

2018-02/c++

(25)
string manipulations ( pointers ) string append 할 일이 생기는 경우:vector 을 사용해 reserve 후 append 해서 string sam(t.begin(),t.end()) 해도 되고후에 복사하는 시간 아끼려면string sam = ""sam.reserve(100)// 될꺼 같았는데 안돔 ㅜㅜ// 걍 벡터에 옮겨서 작업해야될지도? 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091..
strings(3) 1234567891011121314151617181920212223242526272829303132#include "stdafx.h"#include #include #include #include using namespace std; void reverse(char * tmp) { char * end = tmp; while (*end) { end++; } end--; while (tmp
Strings(2) 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485#include "stdafx.h"#include #include #include #include using namespace std; void touppercase(char * sam) { while (*sam) { if (*sam >= 'a' && *sam sam) { char tmp = *end; *end = *sam; *sam = tmp; sam++; end--; }} bool duplicate(string s) ..
relational data structures & strings (C++ STL) 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816..
dynamic allocation of 2-dimension array 12345678910111213141516171819202122232425#include "stdafx.h"#include using namespace std; int main() { int ** tmp; tmp = new int *[10]; for (int i = 0; i
c++ reference variables 1234567891011121314151617181920#include "stdafx.h"#include using namespace std; int func(int & num) { num = num+3; return num+3;} int main() { int num = 50; int & num2 = num; num2 = func(num); num2++; cout
Template classes, operator overloading 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576#include "stdafx.h"#include #define FUNC(X) X*X*X using namespace std; class cl1 {public: int a; int b; cl1() { a = 0; b = 0; } cl1(int aa, int bb) { a = aa; b = bb; } cl1 operator+(cl1 &ref) { return cl1(a + ref.a, b + ref.b); } cl1 operator+(int sam) { ..
time&chronos chrono library 123456789101112131415161718192021222324#include "stdafx.h"#include #include #include using namespace std; long fibonacci(int n) { if (n