โ 2941 ํฌ๋ก์ํฐ์ ์ํ๋ฒณ โ
//2941
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string S;
int x;
cin >> S;
vector<string> arr = {"c=","c-","dz=","d-","lj","nj","s=","z="};
for(int i =0 ; i < arr.size(); i++){
while(true){
x = S.find(arr[i]);
if(x == string::npos){
break;
}
else{
S.replace(x, arr[i].length(), "!");
}
}
}
cout << S.length();
return 0;
}
๐ค vector<string>์ผ๋ก ๋ฌธ์์ด์ด ๋ค์ด๊ฐ ๋ฐฐ์ด์ ์์ฑ(#include <vector>)
๐ค find() ํจ์ ์์ ํฌ๋ก์ํฐ์ ๋ณ๊ฒฝ๋ ์ํ๋ฒณ ๋ฌธ์์ด์ ๋ฃ์ผ๋ฉด, ํด๋น ๋ฌธ์์ด์ด ๋ค์ด๊ฐ๋ ์์น๋ฅผ index๋ก ์ ์ ์๋ค. ๋ง์ฝ ๋ชป์ฐพ์๋ค๋ฉด(x == string.npos) ๋ฐ๋ก ์ข ๋ฃ. 2๊ฐ ์ด์ ์์ ์ ์์ผ๋ฏ๋ก while(true)๋ฌธ ์งํ.
๐ค ์ฐพ์์ ๋์ฒดํด์ผ ํ๋ค๋ฉด replace() ํจ์๋ฅผ ํ์ฉ. replace์ ์ฒซ๋ฒ์งธ ์ธ์ index, ๋๋ฒ์งธ ์ธ์ ํด๋น index์์ ๋ฐ๊ฟ ๊ฐ๊ฒฉ length(), ์ธ๋ฒ์งธ ์ธ์ ๋ฐ๊ฟ ๋ด์ฉ.
โ 2563 ์์ข ์ด โ
//2563
#include <iostream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int paper[100][100] = {0};
int num, ans = 0;
int x, y;
cin >> num;
for(int i = 0; i < num; i++){
cin >> x >> y;
for(int j=y;j<(y+10);j++){
for(int k=x;k<(x+10);k++){
if(!paper[j][k]){
paper[j][k] = 1;
ans+=1;
}
}
}
}
cout << ans << '\n';
return 0;
}
๐ค ์์ด๋์ด ๋ฌธ์ . ์ง์ ๊ฒน์น๋ ๊ฒ ์๊ด์์ด, ์์ญ์ ํด๋น๋๋ ์นธ๋ง 0์ 1๋ก ๋ฐ๊ฟ. ๊ทธ๋ฆฌ๊ณ ์ ์ฌ๊ฐํ์ด๋ฏ๋ก ๋ฐฉํฅ ๊ณ ๋ ค ์์ด x์์ x+9๊น์ง, y์์ y+9๊น์ง ๋จ์ํ for๋ฌธ ๋๋ฆฌ๋ฉด ๋จ. ์ด ๋ 2์ฐจ์ ๋ฐฐ์ด ๋ง๋ค ๋ ์ฒ์์ {0}์ผ๋ก ์ด๊ธฐํ ํ์
'C, C++ > ๐ฅ BOJ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
(C++) โ Stack & Queue & Deque Intermediate I - 4 Solvedโ (0) | 2024.11.15 |
---|---|
(C++) โ Number Theory Intermediate I - 2 Solvedโ (0) | 2024.11.15 |
(C++) โ Set/Map Intermediate I - 5 Solvedโ (2) | 2024.11.14 |
(C++) โ Sorting Intermediate I - 5 Solvedโ (0) | 2024.11.14 |
(C++)โ BF Intermediate I - 1 Solvedโ (0) | 2024.11.14 |
๋๊ธ