');}.category-filters a:hover .checkbox {border-color: #dd3333;}.checkbox .check-table svg {stroke:#dd3333;}html{scroll-behavior:smooth;}.content-area .article-loop-featured:nth-child(3),.content-cluster .article-loop-featured:nth-child(3){margin-bottom:3rem;}.article-content,#commentform input, #commentform textarea,.reply a,.woocommerce #respond input#submit, .woocommerce #respond input#submit.alt,.woocommerce-address-fields__field-wrapper input,.woocommerce-EditAccountForm input,.wpcf7-form input,.wpcf7-form textarea,.wpcf7-form input.wpcf7-submit,.grid-container .grid-item,.featured-post-img,.regular-post-img,.lastest-post-img {border-radius:10px !important;}.pagination a, .pagination span, .nav-links a {border-radius:50%;min-width:2.5rem;}.reply a {padding:6px 8px !important;}.asap-icon,.asap-icon-single {border-radius:50%;}.asap-icon{margin-right:1px;padding:.6rem !important;}.content-footer-social {border-top-left-radius:10px;border-top-right-radius:10px;}.item-featured,.item-new {border-radius:2px;}.content-item-category > span {border-top-left-radius: 3px;border-top-right-radius: 3px;}.woocommerce span.onsale,.woocommerce a.button,.woocommerce button.button, .woocommerce input.button, .woocommerce a.button.alt, .woocommerce button.button.alt, .woocommerce input.button.alt,.product-gallery-summary .quantity input,#add_payment_method table.cart input,.woocommerce-cart table.cart input, .woocommerce-checkout table.cart input,.woocommerce div.product form.cart .variations select {border-radius:2rem !important;}.search-home input {border-radius:2rem !important;padding: 0.875rem 1.25rem !important;}.search-home button.s-btn {margin-right:1.25rem !important;}#cookiesbox p,#cookiesbox a {color: #FFFFFF;}#cookiesbox button {background: #FFFFFF;color:#dd3333;}@media (max-width: 1050px) and (min-width:481px) {.article-loop-featured .article-image-featured {border-radius: 10px !important;}}@media (min-width:1050px) { #autocomplete-results {border-radius:3px;}ul.sub-menu,ul.sub-menu li {border-radius:10px;}.search-header input {border-radius:2rem !important;padding: 0 3 0 .85rem !important;}.search-header button.s-btn {width:2.65rem !important;}.site-header .asap-icon svg { stroke: #FFFFFF !important;}.home .content-loop {padding-top: 1.75rem;}.article-loop-featured:first-child .article-image-featured {border-top-left-radius:10px !important;}.article-loop-featured:nth-child(1) .article-image-featured {border-bottom-left-radius:10px !important;}.article-loop-featured:nth-child(3) .article-image-featured {border-top-right-radius:10px !important;}.article-loop-featured:nth-child(3) .article-image-featured {border-bottom-right-radius:10px !important;}.primary-sidebar .article-image-featured {border-radius:10px !important;}}.article-content {height:196px;}.content-thin .content-cluster .article-content {height:160px !important;}.last-post-sidebar .article-content {height: 140px;margin-bottom: 8px}.related-posts .article-content {height: 120px;}.asap-box-design .related-posts .article-content {min-height:120px !important;}.asap-box-design .content-thin .content-cluster .article-content {heigth:160px !important;min-height:160px !important;}@media (max-width:1050px) { .last-post-sidebar .article-content,.related-posts .article-content {height: 150px !important}}@media (max-width: 480px) {.article-content {height: 180px}}@media (min-width:480px){.asap-box-design .article-content:not(.asap-box-design .last-post-sidebar .article-content) {min-height:196px;}.asap-loop-horizontal .content-thin .asap-columns-1 .content-cluster .article-image,.asap-loop-horizontal .content-thin .asap-columns-1 .content-cluster .article-content {height:100% !important;}.asap-loop-horizontal .asap-columns-1 .article-image:not(.asap-loop-horizontal .last-post-sidebar .asap-columns-1 .article-image), .asap-loop-horizontal .asap-columns-1 .article-content:not(.asap-loop-horizontal .last-post-sidebar .asap-columns-1 .article-content) {height:100% !important;}.asap-loop-horizontal .asap-columns-2 .article-image,.asap-loop-horizontal .asap-columns-2 .article-content,.asap-loop-horizontal .content-thin .asap-columns-2 .content-cluster .article-image,.asap-loop-horizontal .content-thin .asap-columns-2 .content-cluster .article-content {min-height:140px !important;height:100% !important;}.asap-loop-horizontal .asap-columns-3 .article-image,.asap-loop-horizontal .asap-columns-3 .article-content,.asap-loop-horizontal .content-thin .asap-columns-3 .content-cluster .article-image,.asap-loop-horizontal .content-thin .asap-columns-3 .content-cluster .article-content {min-height:120px !important;height:100% !important;}.asap-loop-horizontal .asap-columns-4 .article-image,.asap-loop-horizontal .asap-columns-4 .article-content,.asap-loop-horizontal .content-thin .asap-columns-4 .content-cluster .article-image,.asap-loop-horizontal .content-thin .asap-columns-4.content-cluster .article-content {min-height:100px !important;height:100% !important;}.asap-loop-horizontal .asap-columns-5 .article-image,.asap-loop-horizontal .asap-columns-5 .article-content,.asap-loop-horizontal .content-thin .asap-columns-5 .content-cluster .article-image,.asap-loop-horizontal .content-thin .asap-columns-5 .content-cluster .article-content {min-height:90px !important;height:100% !important;}}.article-loop .article-image,.article-loop a p,.article-loop img,.article-image-featured,input,textarea,a { transition:all .2s; }.article-loop:hover .article-image,.article-loop:hover img{transform:scale(1.05) }.the-content .post-index {background:#dd33331A !important;border:1px solid #dd3333 !important;}.the-content .post-index .checkbox .check-table svg {stroke-width:1 !important;}@media(max-width: 480px) {h1, .archive .content-loop h1 {font-size: calc(38px - 8px);}.asap-hero h1 {font-size: calc(32px - 8px);}h2 {font-size: calc(32px - 4px);}h3 {font-size: calc(28px - 4px);}.article-loop-featured .article-image-featured {border-radius: 10px !important;}}@media(min-width:1050px) {.content-thin {width: calc(95% - 300px);}#menu>ul {font-size: calc(18px - 2px);} #menu ul .menu-item-has-children:after {border: solid #FFFFFF;border-width: 0 2px 2px 0;}}@media(max-width:1050px) {#menu ul li .sub-menu li a:hover { color:#dd3333 !important;}#menu ul>li ul>li>a{font-size: calc(18px - 2px);}} .asap-box-design .last-post-sidebar .article-content { min-height:140px;}.asap-box-design .last-post-sidebar .article-loop {margin-bottom:.85rem !important;} .asap-box-design .last-post-sidebar article:last-child { margin-bottom:2rem !important;}.asap-date-loop {font-size: calc(18px - 5px) !important;text-align:center;}.sticky {top: 22px !important;}.the-content h2:before,.the-content h2 span:before{margin-top: -20px;height: 20px;}header {position:relative !important;}@media (max-width: 1050px) {.content-single,.content-page {padding-top: 0 !important;}.content-loop {padding: 2rem;}.author .content-loop, .category .content-loop {padding: 1rem 2rem 2rem 2rem;}}.site-header {box-shadow: 0 1px 12px rgb(0 0 0 / 30%);}.content-footer .widget-area {padding-right:2rem;}footer {background: #dd3333;}.content-footer {padding:20px;}.content-footer p.widget-title {margin-bottom:10px;}.content-footer .logo-footer {width:100%;align-items:flex-start;}.content-footer-social {width: 100%;}.content-single,content-page {margin-bottom:2rem;}.content-footer-social > div {max-width: calc(980px - 32px);margin:0 auto;}.content-footer .widget-bottom-area {margin-top:1.25rem;}.content-footer .widget-bottom-title {display: none;}@media (min-width:1050px) {.content-footer {padding:30px 0;}.content-footer .logo-footer {margin:0 1rem 0 0 !important;padding-right:2rem !important;}}@media (max-width:1050px) {.content-footer .logo-footer {margin:0 0 1rem 0 !important;}.content-footer .widget-area {margin-top:2rem !important;}}.search-header input {background:#FFFFFF !important;}.search-header button.s-btn,.search-header input::placeholder {color: #484848 !important;opacity:1 !important;}.search-header button.s-btn:hover {opacity:.7 !important;}.search-header input:not([type=submit]):not([type=radio]):not([type=checkbox]):not([type=file]) {border-color: #FFFFFF !important;}@media(min-width:768px) {.grid-container .grid-item.item-2 h2,.grid-container .grid-item.item-4 h2 {font-size: calc(25px - 8px) !important;}}
UVA Solution for 673 Parentheses Balance - Java
Esta es una propuesta de solución para el ejercicio de UVA 673 Parentheses Balance en el lenguaje de programación Java.
Java codec solution for "673 Parentheses Balance"
Esta es una propuesta de solución sencilla. Aunque su tiempo o time limit no es tan bueno, es suficiente para obtener el accepted.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Main {
static class Pila extends ArrayList{
public void agregar(Object elemento) {
if(elemento != null){
this.add(elemento);}
}
/*
* Elimina el primer elemento de la pila.
* @see estructura.Estructura#eliminar()
*/
public Object eliminar() {
Object temp = this.get(0);
if(this.size() > 0){
this.remove(this.size()-1);
}
return temp;
}
public boolean esVacio() {
return this.isEmpty();
}
/*
* Este metodo recupera primer elemento de la pila.
* @see estructura.Estructura#top()
*/
public Object top() {
Object datoAuxiliar = null;
if(this.size() > 0){
datoAuxiliar = this.get(this.size()-1);
}
return datoAuxiliar;
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int line = Integer.parseInt(br.readLine());
while (line-- != 0) {
boolean bad = false;
char[] arChars = br.readLine().toCharArray();
Pila pila = new Pila ();
for (char c : arChars) {
if (c == '[' || c == '(') {
pila.agregar(c);
} else {
if (c == ']') {
if (pila.esVacio() || (char)pila.top() == '(')
bad |= true;
} else if (c == ')') {
if (pila.esVacio() || (char)pila.top() == '[')
bad |= true;
}
if (!pila.isEmpty())
pila.eliminar();
}
}
if (!pila.isEmpty())
bad = true;
System.out.println(bad ? "No" : "Yes");
}
}
}
Espero que te sea de gran ayuda. No olvides calificar este articulo.
Si quieres conocer otros artículos parecidos a UVA Solution for 673 Parentheses Balance - Java puedes visitar la categoría Java.
Subir
Entradas relacionadas