본문 바로가기

Algorithm/Lecture

알고리즘 풀이를 위한 C/C++/STL 기초 정리 - C언어편

 

##  C/C++/STL 기초

 

[https://docs.google.com/document/d/1xrhb-6Vm5_0zd2iImbdg_4kN2cTnY-ZSzyrFAavwABI/edit?usp=sharing](https://docs.google.com/document/d/1xrhb-6Vm5_0zd2iImbdg_4kN2cTnY-ZSzyrFAavwABI/edit?usp=sharing)

 

Algorithm Note - 1. C/C++/STL

// C/C++/STL 기초 ------------------------------------------------------------------------------------------ C언어 //1.1 포멧 문자열 int %d 10진수 %x 16진수 %o 8진수 long long %lld %I64d char %c char* %s float %f double %lf long double %Lf //1.2 TestCase 또는 EOF 받기 //Tets

docs.google.com

C언어

 

//1.1 포멧 문자열

 

int %d 10진수 %x 16진수 %o 8진수

long long %lld %I64d

 

char %c char\* %s

float %f double %lf long double %Lf

 

//1.2 TestCase 또는 EOF 받기

 

//TetsCase

int cases; cin>>cases; while(cases--){...}

 

//EOF 까지

 

while(scanf("%d %d",&a,&b)==2){...}

while(scanf("%d %d",&a,&b)!=EOF){...}

while(c = getchar() && c!= EOF){...}

 

// TestCase EOF 같이 있는 경우 -> 독립적으로 생각

 

// %c는 공백문자 ' ' = 32 와 줄바꿈 문자 '\n'=10 을 받으므로 주의!!.

// scanf안의 공백은 공백이나 줄바꿈을 무시 하게 한다. scanf("%c %c"..)

 

//1.3 scanf의 공백 및 줄 바꿈 처리, 한줄 입력 받기

 

//(1)

scanf("%d\n",&n);

scanf("%c %c %c",&x,&y,&z);

//(2)

scanf(" %c %c %c",&x,&y,&z);

//(3)

scanf("%[^\n]\n",s); // s 에 char s[] 문자배열형

//(4)

fgets() //줄바꿈 포함 한줄 입력 가능

 

//1.4

scanf("%[123]",s);

scanf("%[^123]",s);

 

//1.5 문장의 앞뒤 공백도 다 입력 받고 싶다면?

while( (c = getchar()) && c!= EOF){

print("%c",c);

}

 

//1.6 scanf 지정한 갯수만 입력받기

scanf("%ld",&x); //1234입력-> 1,2,3,4 1개씩 scanf

scanf("%10s",s); // 문자열 길이가 10개 (이하) 씩 받음

 

//1.7 scanf 형식을 만들어서 입력받기

scanf("%d,%d",&x,&y); // 10,20 이런식의 좌표를 받을 수 있음.

//주의

while(scanf(...))는 EOF입력시 리턴값이 -1 이 되어 while(참)이 되어 무한루푸에 빠질 수 있음

 

 

DOS IMPACT - WEB Developer

KIM DO YOUNG

WEB : REACT JS | REACT NATIVE | GraphQL PRISMA