No older revisions available
No older revisions available
MedusaCppStudy 신애 숙제 ¶
*정사각형짜기*
~cpp #include <iostream> #include <string> using std::cin; using std::endl; using std::cout; using std::string; int main() { cout << "숫자를 써 넣으시오: "; int num; cin >> num; int rows = num; int cols = num * 2 - 1; cout << endl; for (int r = 0; r != rows; r++) { string::size_type c = 0; while (c != cols) { if (r == 0 || r == rows -1 ) { if (c % 2 == 0) cout << "*"; else cout << " "; } else if ( c == 0 || c == cols-1 ) { cout << "*"; } else cout << " "; c++; } cout << endl; } return 0; }
*직사각형 짜기*
~cpp #include <iostream> #include <string> using std::cin; using std::endl; using std::cout; using std::string; int main() { cout << "숫자를 써 넣으시오: "; int a,b; cin >> a; cin >> b; int rows = a; int cols = b * 2 - 1; cout << endl; for (int r = 0; r != rows; r++) { string::size_type c = 0; while (c != cols) { if (r == 0 || r == rows -1 ) { if (c % 2 == 0) cout << "*"; else cout << " "; } else if ( c == 0 || c == cols-1 ) { cout << "*"; } else cout << " "; c++; } cout << endl; } return 0; }
*정삼각형 짜기*
~cpp #include <string> #include <iostream> using std::cin; using std::endl; using std::cout; using std::string; int main() { cout << "숫자를 써 넣으시오:"; int num; cin >> num; int rows = num; int cols = num * 2 - 1; for (int r = 0; r != rows; r++ ) { string::size_type c = 0; while ( c != cols) { if (r == rows - 1) { if (c % 2 == 0) cout << "*"; else cout << " "; } else if (r == 0 ) { if ( c == num - 1) cout << "*"; else cout << " "; } else { if (c == num - 1 - r || c == num - 1 + r) cout << "*"; else cout << " "; } c++; } cout << endl; } return 0; }*정수대입해서 큰수 4개찾기*
~cpp #include <iostream> #include <vector> #include <algorithm> using std::cin; using std::cout; using std::endl; using std::vector; using std::sort; int main() { cout << "정수값을 입력하시오:"; int count = 0; int x; vector<int> number; while (cin >> x) { number.push_back(x); count++; } sort(number.begin (),number.end()); if (count >= 4) { cout << number[number.size() - 4] << "," << number[number.size() - 3] << "," <<number[number.size() - 2] << "," <<number[number.size() - 1]; } else { for ( int i=0; i < number.size() ;i++) cout << number[i] << ","; } return 0; }*string의 길이 긴것과 짧은것 찾기*
~cpp #include <iostream> #include <algorithm> #include <vector> #include <string> using std::cin; using std::cout; using std::endl; using std::vector; using std::sort; using std::string; int main() { cout << "문자열을 입력하시오:"; string x; vector<int> english; while (cin >> x) { if ( x == ";") break; else english.push_back(x.size()); } sort (english.begin(),english.end()); cout << endl; cout << english[english.size()-1] << "," << english[0]; return 0; }*마방진 짜기*
~cpp #include <iostream> #include <vector> using std::cin; using std::cout; using std::endl; using std::vector; int main() { cout << "숫자를 입력하시오:"; int num; cin >> num; vector< vector <int> > board(num); for ( int i = 0 ; i < num ; i++) board[i].resize(num); for(int r = 0; r < num; r++) { for(int c = 0; c < num; c++) { cout << board[r][c] << "\t"; } cout << endl; } return 0; }