-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8-g0rnn #35
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λ λ¬Έμ λ‘ κ½κ½ λλ¬λ΄μμ£Όμ ¨λ€μ..
μ μν¨ λ¬Έμ λ regex μ¬μ©λ²μ μ°Ύλ μκ° λΉΌλ©΄
λ¬Έμ μ½λ μκ° > νΈλ μκ° μ΄μμ΅λλ€.
보μλ§μ regex ννμμΌλ‘ νλ°©μ ν μ μκ² κ΅¬λ λΌκ³ μκ°νμ΅λλ€.
λ¬Έμ λ.. μ κ° regexννμμ λͺ»λ§λλ κ² μ
λλ€.
κ·Όλ° λ¬Έμ μμ regexννμμΌλ‘ λ λ¨Ήμ¬μ£ΌλλΌκ΅¬μ
κ·Έλμ cpp μμ regexλ₯Ό νννλ λ°©μμ 곡λΆνκ³ , ~μ +λ‘ λ°κΎΈλ μ½κ² νλ Έμ΅λλ€!
μ§κΈκΉμ§ regexλ§λλ©΄ ννΌν΄μλλ°... μ΄λ²μ μ‘°κΈ κ³΅λΆν΄λ΄€μ΅λλ€...
CPP CODE
#include <iostream>
#include <string>
#include <regex>
using namespace std;
bool isMatched(const string& str){
regex r("(100+1+|01)+");
return regex_match(str, r);
}
int main (){
string str;
cin >> str;
if (isMatched(str)) cout << "SUBMARINE";
else cout << "NOISE";
return 0;
}
μ λμ¬ λ¬Έμ λ μκ°μ΄ κ½€ κ±Έλ Έμ΅λλ€.
μ λ ¬, μ λμ¬ νμΈ λ λ€ λΉ λ₯΄κ² μκ°νκ³ κ΅¬νλ μ νμμ§λ§....
μ λμ¬λ₯Ό νμΈνκ³ μ΄λ»κ² μΉ΄μ΄νΈλ₯Ό ν΄μΌν μ§μλν λ°©ν₯μ μλͺ»μ‘μμμ΅λλ€.
κ· νΈλ μ½λ μ΄μ§ 컨λνλλ° μ μ΄κ±°κ΅¬λ νμ΅λλ€.
μ΅λκ°μ ꡬνλ κ²μ΄λκΉ and μ λ ¬μ νλκΉ, μμμ λΆν° 보면μ,
μ΅λκ°μΌλ‘ μΈν
ν΄λκ³ λΆλΆμ§ν©μ΄ λ μ μλ κ²μ μ³λ΄λ κ·Έλ° λ‘μ§μ΄ λ¨Ήνλ€λ κ²μ μ΄ν΄νμ΅λλ€.
CPP CODE
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int N;
vector<string> str;
bool isPrefix(const string& sub, const string& s) {
return s.find(sub) == 0;
}
int main() {
cin >> N;
str = vector<string>(N);
for (int i = 0; i < N; i++) {
cin >> str[i];
}
sort(str.begin(), str.end());
int result = N;
for (int i = 0; i < N - 1; i++) {
for (int j = i + 1; j < N; j++) {
if (isPrefix(str[i], str[j])) {
result--;
break;
}
}
}
cout << result;
return 0;
}
int answer = n; | ||
for (int i = 0; i < n - 1; i++) { | ||
for (int j = i + 1; j < n; j++) { | ||
if (isStartWith(prefix[j], prefix[i])) { | ||
// μ λμ¬κ° μμΌλ©΄ iλ²μ§Έ λ¨μ΄λ₯Ό μμ° | ||
// μ λ ¬νμΌλ μμ λ³΄λ€ λ¬Έμμ΄μ΄ κΈ΄κ²λ§ λ³΄λ©΄λ¨ | ||
answer--; | ||
break; | ||
} | ||
} | ||
} | ||
cout << answer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λΆλΆ μ§ν©μ κ°―μλ₯Ό ꡬνλ λ¬Έμ λ₯Ό νλ
μ λ΅μ μ΅λμΉλ₯Ό μ ν΄λκ³ λΉΌλκ²λ μ’μ λ°©λ²μΈκ² κ°λ€μ
μ λ μκ°μ΄ μλμ 컨λ νμ΅λλ€...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ¬κΈ°μλ λΆλΆμ§ν©μ μ΅λν¬κΈ°λ₯Ό ꡬνλ κ²μ΄λΌμ λ¨Ήνκ² κ°μμ. κ³ μνμ ¨μ΅λλ€ :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import re
def submarine_sound(sound):
# μ κ· ννμ ν¨ν΄
pattern = re.compile(r"^(100+1+|01)+$")
# ν¨ν΄ λ§€μΉ νμΈ
if pattern.match(sound):
return "SUBMARINE"
else:
return "NOISE"
# μ
λ ₯
sound = input().strip()
# κ²°κ³Ό μΆλ ₯
print(submarine_sound(sound))
μ κ·ννμμΌλ‘ κ°λ¨νκ² ν μ μμμ΅λλ€!
μ½ν
1λ²λ¬Έμ μ μμ£Ό λμ¬κ²κ°μ λ¬Έμμ΄ μ νμΈκ² κ°μ΅λλ€. κ°νΉκ°λ€ μν리λ,,
π λ¬Έμ λ§ν¬
μ μν¨μλ³
μ λμ¬
βοΈ μμλ μκ°
30m
β¨ μλ μ½λ
μ μν¨ μλ³
ꡬνμ μ΄λ μ λ λκ±° κ°μ λ¬Έμμ΄λΆν° λ€μ μμνλ €κ³ λ¬Έμμ΄ λ¬Έμ λ₯Ό 보λλ° μ€μ λ¬Έμ ν°μ΄λ³΄λ€ λμ΄λκ° κ·Έλ¦¬ λμ§ μλκ΅°μ..
μλμ½λλ₯Ό 보면 μ μ μλ―μ΄ regexλ₯Ό μλ©΄ μ λ§ μ½κ² ν리λ λ¬Έμ μ λλ€. μ¬μ€ μ΄λ¬Έμ λ₯Ό νκΈ°μ μ regexλ₯Ό μ¬μ©νμ§ μκ³ νμ΄λ³ΌκΉ νλλ° κ·Έλ κ² μλ―Έμλ 건 μλλΌκ³ μκ°ν΄ regexλ₯Ό λ€μ 곡λΆνμλ λ§μμΌλ‘ regexλ₯Ό μ¬μ©νμ΅λλ€.
regexλ μ λ§ μ€μνλ λ¬Έλ²μ μ΅νλμκΈΈ λ°λλλ€!!!!!
μ λμ¬
μ΄κ²λ λ¬Έμ λ₯Ό 보μλ§μ javaμ startWithμ μκ°νμ΅λλ€. cppμμλ μμ΄μ ꡬνν΄μ μ΄λ€κ³ νλ€μ. λ¬Όλ‘ cpp21μλ μκΈ΄νμ§λ§ μ λ 21λ²μ μ μ¬μ©νμ§ μκΈ°μ κ·Έλ₯ compareλ₯Ό μ¬μ©ν΄μ λ§λ€μμ΅λλ€.
μκ°λ³΅μ‘λλ₯Ό μ‘°κΈμ΄λλ§ μ€μ΄κΈ° μν΄ λ¬Έμμ΄μ κΈΈμ΄λ₯Ό ν λλ‘ μ λ ¬ν ν λ¬Έμ λ₯Ό νμμ΅λλ€.
π μλ‘κ² μκ²λ λ΄μ©
cppμμ regexμ μ¬μ©