목록C++ (28)
사자자리

https://www.acmicpc.net/problem/2739 2739번: 구구단 N을 입력받은 뒤, 구구단 N단을 출력하는 프로그램을 작성하시오. 출력 형식에 맞춰서 출력하면 된다. www.acmicpc.net #include using namespace std; int main() { int n; cin >> n; for (int i = 1; i < 10; i++) { cout
조건문 if #include using namespace std; int main() { int judge; for (int i = 0; i judge; if (judge == 1) cout
반복문 for #include using namespace std; int main() { for (int i = 0; i < 5; i++){ cout

https://www.acmicpc.net/problem/1157 1157번: 단어 공부 알파벳 대소문자로 된 단어가 주어지면, 이 단어에서 가장 많이 사용된 알파벳이 무엇인지 알아내는 프로그램을 작성하시오. 단, 대문자와 소문자를 구분하지 않는다. www.acmicpc.net #include using namespace std; int main() { int alphabet[26] = {0}, max = 0, max_alpha, max_count = 0; string word; cin >> word; for (int i = 0; i < word.length(); i++) {//ASCII 코드를 사용하여 대소문자 문제 해결 if (word[i] < 97) alphabet[word[i] - 65]++;//..

https://www.acmicpc.net/problem/8958 8958번: OX퀴즈 "OOXXOXXOOO"와 같은 OX퀴즈의 결과가 있다. O는 문제를 맞은 것이고, X는 문제를 틀린 것이다. 문제를 맞은 경우 그 문제의 점수는 그 문제까지 연속된 O의 개수가 된다. 예를 들어, 10번 문제의 점수 www.acmicpc.net #include #include using namespace std; int main() { int n, score = 0, sum = 0; char test[80]; cin >> n; for (int i = 0; i > test; for (int j = 0; j < strlen(test); j++) { if (test[j] == 'O') scor..
포인터(pointer) - 사용할 주소에 이름을 붙인다. - 간접 참조 연산자: * - 주소 연산자: & #include using namespace std; int main() { int a = 10; int* ptr = &a; cout
구조체(struct) - 배열: 같은 데이터형의 집합 - 구조체: 다른 데이터형이 허용되는 데이터의 집합 #include using namespace std; int main(){ struct Player{ string name; float height; }A; A.name = "Sirius Black";//구조체 멤버 연산자 '.' A.height = 186.7; Player B = {"Regulus Black", 176.7};//초기화 Player C = {};//빈 값은 0으로 저장된다. Player D[2] = {{"James Potter", 188.5}, {"Remus Lupin", 181.3}};//구조체 배열 cout
복합 데이터형 - 기본 정수형과 부동소수점형의 조합 배열(Array) - 같은 데이터형의 집합 배열의 선언 데이터형배열명[배열의크기]; shortmonth[12];//month 배열의 원소들은 모두 short형이어야 한다. 배열의 초기화 - 초기화는 선언할 때만 할 수 있다. - 배열을 부분적으로 초기화하면, 나머지 원소들은 모두 0으로 설정된다. - 배열을 초기화할 때 대괄호 속을 비워두면, 컴파일러가 초기화 값의 개수를 배열의 크기로 저장한다. short month[12] = {1, 2, 3}; short credit[] = {1, 2, 3};//배열의 크기가 자동으로 3이 된다. 배열의 원소를 출력하기: 인덱스 #include using namespace std; int main() { short ..