Português
Abrir no Telegram

Tópico Mensagem #1738

2 mensagens · –
  1. K
    import java.util.Arrays; import java.util.Scanner; import java.util.Stack; public class Solution { private static final Stack<Integer> signs = new Stack<>(); public static boolean solve(int[] str, int k, int val, int sign, int index) { if (index == str.length) { return val == k; } val += sign * str[index]; if (solve(str, k, val, 1, index+1) || solve(str, k, val, -1, index+1)) { signs.push(sign); return true; } return false; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int len = sc.nextInt(), k = sc.nextInt(); int[] str = Arrays.stream(sc.next().split("\\*")).mapToInt(s -> s.charAt(0)-48).toArray(); sc.close(); if (solve(str, k, 0, 1, 0)) { if (!signs.isEmpty()) { signs.pop(); } int i = 1; System.out.print(str[0]); while (!signs.isEmpty()) { System.out.print((signs.pop() == 1? "+": "-") + str[i++]); } } } }

Um feed público aberto do índice de busca ChatCrawler — “o Google do Telegram público”; atualizado à medida que a comunidade é rastreada. Horários em UTC.

Somente conteúdo público, API oficial do Telegram. Sobre · Perguntas frequentes · Limites do índice · Remover uma página · Catálogo · Busca · Como calculamos