프로그래밍 대회에 필요한 지식

2019. 3. 8. 01:46·공부 ✨/알고리즘


기본 

if else

1
2
3
if (a % 2 ==0 ) return 1;
else return 0;
 
cs


for

1
2
3
4
5
6
int sum =0;
for (int i =1 ; i < n ; i++)
{
    sum += i ;
}
return sum;

cs



배열


C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <algorithm>
#include <vector>
 
using namespace std;
 
int getMaxNum (vector<int> array)
{
    int ret = array[0];
    for (int i =1 ; i< array.size(); i++)
    {
        if (ret < array[i]) ret = array[i];
        
    }
    return ret; 
}
Colored by Color Scripter
cs




제출 형식


문제 : int 형의 매개변수 a,b가 주어질 때 a+b를 리턴하세요
class : AplusBProblem
method : public int calc(int a, int b)


C++


using namespace std;


class AplusBproblem

{    

public : 

int calc(int a, int b)

{

return a+b;

}

};




추가로 알면 편리한 지식



정렬

C++
#include <algorithm>

sort(array);



JAVA

inport java.util.*;

Arrays.sort(array);



C#

using System;


System.Array.Sort(array);




문자열 처리


C++
string s ="abc";

// 동일 판정
if(s == "abc") cout <<"equal" << endl;    

//문자 하나 추출
char c = s[1]; // 'b'

//문자열 연결
s = "def" + s + "ghi";    // "defabcghi"

//문자열 잘라내기
s = s.substr(3,3);   //"abc"



연관 배열 

C++ 이면 map 클래스 , java 라면 Hashmap 클래스 , C# 이면 Dictionary  클래스 등의 자료구조가 연관 배열 이다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <map>
 
 
void countString(vector<string>s)
{
    map<string, int>m;
    for (int i =0; i< s.size(); i++)
    {    
        m[s[i]]++;
 
    }
    map<string, int> :: iterator it = m.begin();
    while(it != m.end())
    {
        cout << (*it).first << "" << (*it).second << endl;
        ++it;
    }
}
Colored by Color Scripter
cs









저작자표시 비영리 변경금지 (새창열림)
'공부 ✨/알고리즘 ' 카테고리의 다른 글
  • 백준 알고리즘 단계별 문제풀이 솔루션
  • Introduction to Algorithms 답지
  • STL 정리
  • codeground 자료 구조
hjc_
hjc_
  • hjc_
    개인노트
    hjc_
  • 전체
    오늘
    어제
    • 분류 전체보기 (130)
      • 일상 ✨ (1)
      • 책 읽기 ✨ (4)
      • 자유게시판 ✨ (25)
      • 영어공부 ✨ (20)
        • 오늘의 영어 (5)
        • 매일 20문장 영어 회화 (8)
        • 공부 자료 (7)
      • 공부 ✨ (78)
        • C (13)
        • JAVA (26)
        • JSP (1)
        • Python (2)
        • 머신러닝 & 딥러닝 (6)
        • 리눅스 (4)
        • 자료구조 (7)
        • 알고리즘 (8)
        • 네트워크 보안 (2)
        • 컴퓨터 구조 (1)
        • 데이터 베이스 (1)
        • 공부 자료 (7)
      • 실습 ✨ (0)
      • 프로젝트 ✨ (0)
  • 블로그 메뉴

    • 홈
  • 링크

    • dynalist :: 계획, 프로젝트 관리
    • 비캔버스 :: 온라인 화이트 보드
  • 공지사항

  • 인기 글

  • 태그

    Introduction to Algorithms
    답
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.0
hjc_
프로그래밍 대회에 필요한 지식
상단으로

티스토리툴바