1239 - Atalhos Bloggo
O problem setter desse problema facilitou muita coisa para gente, então só bora!
Last updated
O problem setter desse problema facilitou muita coisa para gente, então só bora!
Last updated
#include <string.h>
#include <stdio.h>
int main(){
char frase[51];
int n, negrito, italico;
while(gets(frase) != NULL){
negrito = 0;
italico = 0;
n = strlen(frase);
for(int i = 0; i < n; ++i){
if(frase[i] == '_'){
printf("%s", italico ? "</i>" : "<i>");
italico = 1 - italico;
}else if(frase[i] == '*'){
printf("%s", negrito ? "</b>" : "<b>");
negrito = 1 - negrito;
}else{
printf("%c", frase[i]);
}
}
printf("\n");
}
return 0;
}#include <iostream>
using namespace std;
int main(){
int n;
string frase;
bool negrito, italico;
while(getline(cin, frase)){
negrito = false;
italico = false;
n = frase.length();
for(int i = 0; i < n; ++i){
if(frase[i] == '_'){
cout << (italico ? "</i>" : "<i>");
italico = !italico;
}else if(frase[i] == '*'){
cout << (negrito ? "</b>" : "<b>");
negrito = !negrito;
}else{
cout << frase[i];
}
}
cout << endl;
}
return 0;
}var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.trim().split('\n');
const replaceAll = (frase, simbolo, tagAberta, tagFechada) => {
let novaFrase = frase.replace(simbolo, tagAberta);
let aberta = true;
while(novaFrase !== frase){
frase = novaFrase;
novaFrase = frase.replace(simbolo, aberta ? tagFechada : tagAberta);
aberta = !aberta;
}
return frase;
}
while(lines.length){
let frase = lines.shift();
frase = replaceAll(frase, '_', '<i>', '</i>');
frase = replaceAll(frase, '*', '<b>', '</b>');
console.log(frase);
}def replaceAll(frase, simbolo, tagAberta, tagFechada):
novaFrase = frase.replace(simbolo, tagAberta, 1)
aberta = True
while(novaFrase != frase):
frase = novaFrase
novaFrase = frase.replace(simbolo, tagFechada if aberta else tagAberta, 1)
aberta = not aberta
return frase
while True:
try:
frase = input()
frase = replaceAll(frase, '_', '<i>', '</i>')
frase = replaceAll(frase, '*', '<b>', '</b>')
print(frase)
except EOFError:
break