cyphen156
백준-문자열 9086 문자열 본문
입력받은 문자열의 첫 글자와 마지막 글자를 출력하는 프로그램
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
'컴퓨터공학 > 알고리듬 풀이' 카테고리의 다른 글
백준-문자열 11720 숫자의 합 (0) | 2024.09.24 |
---|---|
백준-문자열 11654 아스키 코드 (0) | 2024.09.21 |
백준-문자열 2743 단어 길이 재기 (0) | 2024.09.19 |
백준-문자열 27866 문자와 문자열 (0) | 2024.09.19 |
백준-1차원 배열 1546 평균 (0) | 2024.09.19 |