본문 바로가기

알고리즘

(62)
그룹 단어 체커 #include #include using namespace std; int cnt; void Checker(string word) { int len = word.size(); for (int i = 0; i > num; for (int i = 0; i > word; Checker(word); } cout
크로아티아 알파벳 #include #include using namespace std; int main() { int cnt = 0; string word; cin >> word; for (int i = 0; i = 0) { word[i] = '0'; } else if (word[i - 1] == 'z' &&i - 1 >= 0) { if (word[i - 2] == 'd' && i - 2 >= 0) { word[i - 1] = '0'; word[i] = '0'; } else word[i] = '0'; } } else if (word[i..
다이얼 #include #include int main(void) { char str[16] = { 0 }; // 배열 생성 int time[] = { 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10 }; //알파벳에 따른 시간 int res = 0; scanf("%s", str); for (int i = 0; i < strlen(str); i++) res += time[str[i] - 'A']; printf("%d \n", res); return 0; } #include #include using namespace std; int main() { char str[16] = { 0 }; int time[] = { 3..
상수 #include using namespace std; int Reverse(int num) { int a = 0, b = 0, c = 0; a = num / 100; b = (num % 100) / 10; c = (num % 100) % 10; return c * 100 + b * 10 + a; } int main() { int num1, num2; int result = 0; cin >> num1 >> num2; if (Reverse(num1) > Reverse(num2)) result = Reverse(num1); else result = Reverse(num2); cout
단어의 개수 #include int main(void) { char str[1000000] = { 0 }; int cnt = 1; gets(str); //공백 처리를 위함 if (str[0] == ' ') //처음 cnt = cnt - 1; for (int i = 0; str[i] != 0; i++) { if (str[i] == ' ') { cnt++; if (str[i + 1] == 0) //마지막 { if (str[i] == ' ') cnt = cnt - 1; } } } printf("%d \n", cnt); return 0; }
단어 공부 #include #include using namespace std; int main() { string s; int arr[26] = { 0 }; int max = 0; char result; getline(cin, s); // 아스키 코드 이용 for (int i = 0; i = 65 && s[i] = 97 && s[i] max) { result = i + 65; max = arr[i]; } else if (arr[i] == max) result = '?'; } cout
문자열 반복 #include int main(void) { char str[20]; int t; // 테스트 케이스 개수 int r; // 반복 횟수 int i, j, k; scanf("%d", &t); for (i = 0; i < t; i++) { scanf("%d %s", &r, str); for (j = 0; str[j] != 0;j++) for (k = 0; k < r; k++) printf("%c", str[j]); printf("\n"); } return 0; }
숫자의 합 #include using namespace std; int main() { char str[100] = { 0 }; int i, num; int sum = 0; cin >> num; cin >> str; for (i = 0; i < num; i++) { sum += str[i]-'0'; } cout