String
아스키코드(ASCII) : 문자 인코딩 방법 중 하나이다.
0=> 48A=> 65a=> 970 => NULL
실습
알파벳 개수
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
string s;
cin >> s;
for (int i='a'; i<='z'; i++) {
cout << count(s.begin(), s.end(), i) << ' ';
}
cout << '\n';
}여기서 #include <algorithm>에서 count(s.begin(),s.end(),i);는 s문자열에서 i가 포함된 수를 count해준다.
알파벳 위치
find(s.begin(), s.end(), i);는 위치를 알려준다.
문자열 분석
문자열 N개에 포함되어 있는 소문자, 대문자, 숫자, 공백의 개수를 세는 문제
단어 길이 재기
strlens.length()s.size()
ROT13
ROT13으로 암호화하는 프로그램을 만드는 문제이다. ROT13은 카이사르 암호의 일종으로 영어 알파벳을 13글자씩 밀어서 만든다.
문자열 -> 정수
#include <string>에서 stoi,stol,stoll등등의 함수를 사용하면 된다.
함수
변화
stoi
string->int
stol
string->long
stoll
string->long long
stof
string->float
stod
string->double
stold
string->long double
stoul
string->unsigned long
stoull
string->unsigned long long
정수 -> 문자열
to_string함수를 사용하면된다.
접미사 배열
문자열 S의 모든 접미사를 사전순으로 정해 놓은 배열이다.
Last updated
Was this helpful?