SOLUTION INFO
C++ · main.cpp
- 작성자
- tony9402
- 공동 작성자
- 없음
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
string s;
getline(cin, s);
int n = s.size();
for(int i=0;i<n;){
if(s[i] == ' '){
i++;
continue;
}
if(s[i] == '<'){
int j=i;
while(j<n&&s[j]!='>') j++;
i = j + 1;
}
int j=i;
while(j<n&&s[j]!=' '&&s[j] != '<') j++;
reverse(s.begin() + i, s.begin() + j);
i = j;
}
cout << s;
return 0;
}
SOLUTION DESCRIPTION
풀이 설명
등록된 풀이 설명이 없습니다.
SOLUTION INFO
Java · Main.java
- 작성자
- lms0806
- 공동 작성자
- 없음
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException{
FastReader rd = new FastReader();
StringBuilder sb = new StringBuilder(), ss = new StringBuilder();
boolean istrue = false;
for(char ch : rd.nextLine().toCharArray()) {
if(ch == '<' || ch == ' ') {
sb.append(ss.reverse());
ss.setLength(0);
sb.append(ch);
if(ch == '<') {
istrue = true;
}
}
else if(ch == '>') {
istrue = false;
sb.append(ch);
}
else {
if(istrue) {
sb.append(ch);
}
else {
ss.append(ch);
}
}
}
if(ss.length() != 0) {
sb.append(ss.reverse());
}
System.out.print(sb);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while(st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble() { return Double.parseDouble(next()); }
String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
SOLUTION DESCRIPTION
풀이 설명
등록된 풀이 설명이 없습니다.
SOLUTION INFO
Python · main.py
- 작성자
- shjeong92
- 공동 작성자
- 없음
import sys
def input():
return sys.stdin.readline().rstrip()
data = input()
answer = ''
temp=[]
length = len(data)
inParen = False
for i in range(length):
if data[i] == '<':
inParen = True
elif data[i] == '>':
inParen = False
if inParen and data[i] == '<' :
if temp:
answer += ''.join(temp[::-1])+'<'
temp=[]
else:
answer +='<'
elif inParen and data[i] != '<':
answer += data[i]
elif not inParen and data[i] =='>':
answer += data[i]
elif not inParen and data[i]!= ' ':
temp.append(data[i])
elif not inParen and data[i]== ' ':
answer += ''.join(temp[::-1])+' '
temp=[]
if temp:
answer+= ''.join(temp[::-1])
print(answer)
SOLUTION DESCRIPTION
풀이 설명
등록된 풀이 설명이 없습니다.