C언어 알파벳 정렬(오름차순, 내림차순) 문제 좀 풀어 주실 수 있는분 계...

C언어 알파벳 정렬(오름차순, 내림차순) 문제 좀 풀어 주실 수 있는분 계...

작성일 2022.12.19댓글 1건
    게시물 수정 , 삭제는 로그인 필요

 1.임의의 알파벳 9개를 대소문자 섞어서 받기 ex) BcoQZyabc

2. ++를 입력하면 BQZ와 같이 대문자만 오름차순으로 출력 
   +-를 입력하면 ZQB와 같이 대문자만 내림차순으로 출력  
  -+를 입력하면 abccoy와 같이 소문자만 오름차순으로 출력
  --를 입력하면 yoccba와 같이 소문자만 내림차순으로 출력

이게 문제인데 어떻게 만들어야할지 모르겠습니다..ㅠㅠ 오늘 밤 12시까지 해야하는데 혹시 풀어 주실 수 있는 분 계실까요.


#c언어 알파벳 순서대로 출력 #c언어 알파벳 판별 #c언어 알파벳 개수 세기 #c언어 알파벳 아스키코드 변환 #c언어 알파벳 대소문자 변환 #c언어 알파벳 숫자 변환 #c언어 알파벳 출력 #c언어 알파벳 정렬 #c언어 알파벳 #c언어 알파벳 삼각형

profile_image 익명 작성일 -

#include <stdio.h>

#include <string.h>

#include <ctype.h>

#define MAX_LEN 10 // Maximum length of the input string

int main() {

char input[MAX_LEN + 1]; // input string (plus one for the null character)

char output[MAX_LEN + 1]; // output string (plus one for the null character)

int len; // length of the input string

char order; // order of the sorting (either '+' or '-')

char case_; // case of the sorting (either '+' or '-')

printf("Enter a string of 9 characters or fewer (including both uppercase and lowercase letters): ");

scanf("%s", input);

len = strlen(input); // get the length of the input string

printf("Enter the order of the sorting (+ for ascending, - for descending): ");

scanf(" %c", &order); // note the space before %c to skip leading whitespace

printf("Enter the case of the sorting (+ for uppercase, - for lowercase): ");

scanf(" %c", &case_); // note the space before %c to skip leading whitespace

// Sort the input string based on the specified order and case

if (order == '+') {

if (case_ == '+') {

// Sort uppercase letters in ascending order

for (int i = 0, j = 0; i < len; i++) {

if (isupper(input[i])) {

output[j++] = input[i];

}

}

} else {

// Sort lowercase letters in ascending order

for (int i = 0, j = 0; i < len; i++) {

if (islower(input[i])) {

output[j++] = input[i];

}

}

}

} else {

if (case_ == '+') {

// Sort uppercase letters in descending order

for (int i = len - 1, j = 0; i >= 0; i--) {

if (isupper(input[i])) {

output[j++] = input[i];

}

}

} else {

// Sort lowercase letters in descending order

for (int i = len - 1, j = 0; i >= 0; i--) {

if (islower(input[i])) {

output[j++] = input[i];

}

}

}

}

// Add a null character to the end of the output string

output[len] = '\0';

printf("Output: %s\n", output);

return 0;

}