Notice
Recent Posts
Recent Comments
«   2025/06   »
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
Today
Total
Archives
관리 메뉴

cyphen156

백준-문자열 9086 문자열 본문

컴퓨터공학/알고리듬 풀이

백준-문자열 9086 문자열

cyphen156 2024. 9. 21. 15:33

9086번: 문자열 (acmicpc.net)

 

입력받은 문자열의 첫 글자와 마지막 글자를 출력하는 프로그램

C언어로는 문자열 저장안하고 문자 두개만을 저장할 것이다.

제약사항

  • 0 < Test T <= 10
  • 0 < string <= 1,000
  • there is no 'spacing' in "str"

주의 사항

없다.

C 풀이

문자열_9086.c

/**
* 백준 9086 문자열
* 입력받은 문자열의 첫 글자와 마지막 글자를 출력하는 프로그램
* C언어로는 문자열 저장안하고 문자 두개만을 저장할 것이다.
* 
* 
* 제한사항
*****************************************
* 0 < Test T <= 10                      *
* 0 < string <= 1,000                   *
* there is no 'spacing' in "str"        *
*****************************************
*
*
*
* 주의
* 없다.
* 
* 풀이시간 10분
*/

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

int main(void)
{
	int T;
    char start, end, input;
    scanf("%d", &T);
    getchar();

    for (int i = 0; i < T; ++i)
    {
        start = '\0';
        end = '\0';
        while(1)
        {
            scanf("%c", &input);
            if (input == '\n')
            {
                printf("%c%c\n", start, end);  
                break;
            }
            if (start == '\0')
            {
                start = input;
            }
            end = input;
        }
    }

	return 0;
}

 

C++ 풀이

문자열_9086.cpp

/**
* 백준 9086 문자열
* 입력받은 문자열의 첫 글자와 마지막 글자를 출력하는 프로그램
* C언어로는 문자열 저장안하고 문자 두개만을 저장할 것이다.
* 
* 
* 제한사항
*****************************************
* 0 < Test T <= 10                      *
* 0 < string <= 1,000                   *
* there is no 'spacing' in "str"        *
*****************************************
*
*
*
* 주의
* 없다.
* 
* 풀이시간 5분
*/

#include <iostream>
#include <string>

using namespace std;

int main()
{
    int T;

    cin >> T;

    string* s = new string[3];
    for (int i = 0; i < T; ++i)
    {
        string str;        
        cin >> str;

        s[i] += str.front();
        s[i] += str.back();
    }


    for (int i = 0; i < T; ++i)
    {
        cout << s[i] << '\n';
    }
    delete[] s;

    return 0;
}

 

모든 예제 코드의 소스파일은 제 개인 깃허브 레포지토리 에 있습니다.

Workspace/알고리듬 풀이 at main · cyphen156/Workspace · GitHub

 

Workspace/알고리듬 풀이 at main · cyphen156/Workspace

Studying . Contribute to cyphen156/Workspace development by creating an account on GitHub.

github.com