| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include<iostream> #include<string> using namespace std; int main(void) { int c[10]; string sentence; string s1[10]; s1[0] = "0000"; // 0과 1은 문자열 범위에 벗어나는 오류 잡기위해 입력. s1[1] = "0000"; s1[2] = "abca"; s1[3] = "defd"; s1[4] = "ghig"; s1[5] = "jklj"; s1[6] = "mnom"; s1[7] = "pqrs"; s1[8] = "tuvt"; s1[9] = "wxyz"; for (int i = 1; i < 10; i++) { cin >> c[i]; } c[0] = 0; cin >> sentence; int t = 0; for (int i = 0; i < sentence.size(); i++) { int k = 0; int j = 1; while (sentence[i] != s1[c[j]][k]) { //같은 문자를 찾을 때까지 루프를 돌립니다. c[j]는 바뀐 번호가 입력되어있음. j는 원래번호를 의미 if (k < 4) { k++; //길이가 4이므로 k값 case 분류해준다. } if (k == 4) { k = 0; j++; //눌러준번호에서 문자를 못찾으면 다음번호를 누른다 if (j == 10) { throw "not exist"; } } } for (int p = 0; p <= k; p++) { if (t == j) { cout << "#"; //번호 입력뒤에 똑같은 번호가 다시오면 # t = 0; } cout << j; } t = j; } return 0; } | cs |
| cs |
문제 출처:https://www.acmicpc.net/problem/10545
문제 피드백,질문 댓글로 부탁드려요~!