ํ์ด 1
#include <iostream>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
string s; cin >> s;
bool flag = true;
if (s.length() % 2 != 0) { //๊ธธ์ด๊ฐ ํ์์ผ๋
for (int i = 0; i < s.length() / 2; i++) {
if (s[i] != s[s.length() - i-1]) flag = false;
}
}
else { //๊ธธ์ด๊ฐ ์ง์์ผ๋
if (s[s.length() / 2-1] == s[s.length() / 2]) {
for (int i = 0; i < s.length() / 2; i++) {
if (s[i] != s[s.length() - i-1]) flag = false;
}
}
else flag = false;
}
if (flag) cout << "1";
else cout << "0";
}
ํ์ด 2
#include <iostream>
using namespace std;
int main() {
string s; cin >> s;
int N = s.length();
int start = 0;
int end = s.length()-1;
bool flag = true;
while (start <= end) {
if (s[start] != s[end]) flag = false;
start++;
end--;
}
if (flag) cout << "1";
else cout << "0";
}
'Algorithm ๐ง๐ปโ๐ป > ๋ฐฑ์ค(BOJ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค,c++] 11004๋ฒ - K๋ฒ์งธ ์ (0) | 2021.10.26 |
---|---|
[๋ฐฑ์ค,c++] 1100๋ฒ - ํ์ ์นธ (0) | 2021.10.26 |
[๋ฐฑ์ค,c++] 10989๋ฒ - ์ ์ ๋ ฌํ๊ธฐ3 (0) | 2021.10.26 |
[๋ฐฑ์ค,c++] 10987๋ฒ - ๋ชจ์์ ๊ฐ์ (0) | 2021.10.26 |
[๋ฐฑ์ค,c++] 10974๋ฒ - ๋ชจ๋ ์์ด (0) | 2021.10.25 |
[๋ฐฑ์ค,c++] 10973๋ฒ - ์ด์ ์์ด (0) | 2021.10.25 |
๋๊ธ