티스토리 뷰

반응형


#. Problem

* The copyright in this matter is in Inflearn



#. Resolution Process

  1. Read and understand problem

  2. Redefine the problem + abstract

  3. Create solution plan (select Algorithm, Data structure)

  4. Prove the plan (check performance time and usage memory)

  5. Carry out the plan

  6. Look back on the plan and find a way to improve it


#. Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<stdio.h>
 
using namespace std;
 
int main() {
    //freopen("input.txt", "rt", stdin);
    char a[100];
    int i;
 
    gets(a);
 
    for (i = 0; a[i] != '\0'; i++)
    {
        if (a[i] != 32)
        {
            if (a[i] >= 97 && a[i] <= 122)
                printf("%c", a[i]);
            else
                printf("%c", a[i]+32);
        }
    }
 
    return 0;
}
cs

(10) 문자열 한 줄을 한 번에 입력받을 수 있는 gets() 함수


#. Other code

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
#include<stdio.h>
 
using namespace std;
 
int main(){
    //freopen("input.txt", "rt", stdin);
    char a[101], b[101];
    int i, p=0;
 
    gets(a);
    for(i=0; a[i]!='\0'; i++){
        if(a[i]!=' '){
            if(a[i]>=65 && a[i]<=90){
                b[p++]=a[i]+32;
            }
            else b[p++]=a[i];
        }
    }
 
    b[p]='\0';
 
    printf("%s\n", b);    
 
    return 0;
}
cs

로직은 비슷하지만 결과를 따로 저장한 후 출력하는 방법보다

바로 출력해주는 방법이 더 좋은 듯하다.


#. Result

  - Input --------------------------------------------------------

bE    au T I fu   L

------------------------------------------------------------------


  - Output --------------------------------------------------------

beautiful

------------------------------------------------------------------



반응형

'PS > Problem_Solving' 카테고리의 다른 글

[Inflearn] 모두의 약수  (0) 2020.04.20
[Inflearn] 올바른 괄호  (0) 2020.04.20
[inflearn] 숫자만 추출(Amazon interview source)  (0) 2020.04.19
[BOJ] 17614번. 369  (0) 2020.04.19
[BOJ] 1904번. 01타일  (0) 2020.02.04
댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday