String

์•„์Šคํ‚ค์ฝ”๋“œ(ASCII) : ๋ฌธ์ž ์ธ์ฝ”๋”ฉ ๋ฐฉ๋ฒ• ์ค‘ ํ•˜๋‚˜์ด๋‹ค.

  • 0 => 48

  • A => 65

  • a => 97

  • 0 => 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๊ฐœ์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž, ์ˆซ์ž, ๊ณต๋ฐฑ์˜ ๊ฐœ์ˆ˜๋ฅผ ์„ธ๋Š” ๋ฌธ์ œ

๋‹จ์–ด ๊ธธ์ด ์žฌ๊ธฐ

  • strlen

  • s.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?