문자열12 [leetcode 394] Decode String Given an encoded string, return its decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer. You may assume that the input string is always valid; No extra white spaces, square brackets are well-formed, etc. Furthermore, you may assume that the original data .. 2020. 10. 18. [leetcode 5] Longest Palindromic Substring Given a string s, return the longest palindromic substring in s. Example 1: Input: s = "babad" Output: "bab" Note: "aba" is also a valid answer. Example 2: Input: s = "cbbd" Output: "bb" Example 3: Input: s = "a" Output: "a" Example 4: Input: s = "ac" Output: "a" Constraints: 1 2020. 10. 13. [c] 문자열 입력 선언방법 char str[LENGTH]; char *c; 마지막에 null문자(\0)가 저장되니 필요한 길이 +1 해서 저장하자. 1. scanf("%s", s); 문제: 공백문자 못읽음 => scanf("%[^\n]s", s); 를 사용하면 공백을 포함한 문자열 받는게 가능하다. - 참고로 scanf는 저렇게 선언된 포인터형 문자열은 못읽는다... 어떻게 해야 하나! malloc해줘야 한다. 문자열 크기만큼! #include #include int main() { //가능 char *s1 = malloc(sizeof(char) * 10); scanf("%s", s1); free(s1); //에러 char *s2; scanf("%s", s2); return 0; } 2. gets(s); 개행문자('\n'.. 2020. 4. 11. [c++] 문자열 입력받기 문자열 선언 string s char c[LENGTH] 1. cin>>s scanf()와 유사하다. #include using namespace std; int main(void){ string s; cin>>s; } 문제점: 공백이 있으면 잘라버림, 개행 못읽음 ex) hello i am a student를 입력하면 hello만 나온다. 2. getline(cin, s) - getline(istream& is, string& str) - 헤더는 #include #include #include string s; getline(cin, s); - string을 받으므로 char*형은 받지 못한다. - getline은 문자열 자르기에도 사용된다. 문제점: 엔터(개행문자)까지 읽어버려서 버퍼에 엔터가 들어감... 2020. 4. 11. 이전 1 2 3 다음