2 ¶
, ¶
- : 호
- (loop invariant): while 하 하 하 . , 했. 해하, while 행 while 한 한 .( 하 한 ...) 하 하 해. , , .
~cpp //: r 행 함 int r=0; //r 0 팅하 while(r!=rows) { // 할 //한행 하 ( ) std::cout<<std::endl; //r 키 ++r; } // 확할
- 평(short-circuit): if(a==0||b==0){...} a==0 b==0 호 행한 . ||호 |호 하 . 평, 평 .
- 합: 해 했, a+=b, a=a+b 해 형태.
- : 할, for(i=0;i<3;i++)처럼, 시작인 0은 포함하나 3은 포함하지 않고 2에서 끝난다. 이것을 [0,3)으로 표현하는데, 3은 루프 범위에 표현되지 않는 "끝을 벗어난 값"이다.
클 string ¶
- 1 string 클 할 . SeeAlso Yggdrasil/플플/1
~cpp std::string::size_type//unsigned형 , 한. type 하 .
- 1 0 하
- " 하 1 0 " , 퓨 히 하 .
- () 하, [0,5) 5 . 1,5 5 파하 힘.
- 해하 .
- " 하 1 0 " , 퓨 히 하 .
2-1 ¶
- pad 0 화하 .
2-2 ¶
- pad , 킨. , rows, cols 화 화킨.
2-3 ¶
~cpp #include<iostream> #include<string> using std::cin; using std::cout; using std::endl; using std::string; int main() { int pad_rows, pad_cols; cout<<"Please input blank of rows and cols:"; cin>>pad_rows; cin>>pad_cols; cout<<"Please enter your first name: "; string name; cin>>name; const string greeting="Hello, "+name+"!"; const int rows=pad_rows*2+3; const string::size_type cols=greeting.size()+pad_cols*2+2; cout<<endl; for(int r=0;r!=rows;++r) { string::size_type c=0; while(c!=cols) { if(r==pad_rows+1&&c==pad_cols+1) { cout<<greeting; c+=greeting.size(); } else { if(r==0||r==rows-1||c==0||c==cols-1) cout<<"*"; else cout<<" "; ++c; } } cout<<endl; } return 0; }
2-6 ¶
- 1 10 한.
2-7 ¶
- for(int i=10;i>-6;i--) std::cout<
2-8 ¶
~cpp #include<iostream> #include<string> int main() { int sum=1; for(int i=1;i<10;i++) sum*=i; std::cout<<sum; return 0; }