나만 볼 것/코딩테스트 관련 알고리즘?
C++ ) 문자 입력한 수 까지 입력, 형변환, 반올림
xortl98
2022. 2. 10. 22:01
728x90
문자 입력한 수 까지 출력
#include<iostream>
using namespace std;
char a[50];
int main()
{
cin >> a;
for (int i = 0; a[i] != '\0'; i++)
{
cout << a[i] << endl;
}
}
문자열 정수로 변환 외 등등
stoi(변수) = string to int
stof(변수) = string to float
stol(변수) = string to long
stod(변수) = string to double
to_string(변수) = int to string
string변수.substr(n, m) = n~m까지 string 변수 슬라이싱
isupper(char) = 대문자인지 확인, true, false 형태로 나옴
islower(char) = 소문자인지 확인, true, false 형태로 나옴
toupper(char) = 대문자로 변경
tolower(char) = 소문자로 변경
반올림
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
float a = 3.5f;
float b = 5.1f;
cout << round(a) << endl; // 4 출력
cout << round(b) << endl; // 5 출력
float c = 7.54;
c *= 10;
c = round(c);
cout << c / 10 << endl; // 7.5가 출력됨
}
//https://bf-quail.tistory.com/5 참고한 블로그