·
Cursos Gerais ·
Estrutura de Dados
Send your question to AI and receive an answer instantly
Recommended for you
4
Lista de Exercícios Estrutura de Dados - Vetor de Consultas e Rotação
Estrutura de Dados
IFCE
9
Implementacao TAD Matriz em C++ Orientado a Objetos - Lista de Exercicios
Estrutura de Dados
IFCE
8
Analise Empirica de Algoritmos de Ordenacao em Listas Duplamente Encadeadas
Estrutura de Dados
IFCE
7
Analise Comparativa de Algoritmos de Ordenacao - BubbleSort InsertionSort SelectionSort MergeSort e QuickSort
Estrutura de Dados
IFCE
1
Lista de Exercícios de Programação - Listas Filas e Pilhas em C Java Python Ruby
Estrutura de Dados
IFCE
9
Implementação de ForwardList em C++: Concatenação, Remoção e Clonagem
Estrutura de Dados
IFCE
5
Lista de Exercícios Recursão em C - Estrutura de Dados e Algoritmos
Estrutura de Dados
IFCE
7
Projeto 01 Matrizes Esparsas em C - Implementacao de TAD e Operacoes
Estrutura de Dados
IFCE
3
Simulação de Fila de Decolagem e Operações com Pilhas em C
Estrutura de Dados
IFCE
25
Calculando-Altura-e-Numero-de-Nos-em-Arvore-Binaria
Estrutura de Dados
IFCE
Preview text
PROGRESSO PROBLEMA SUBMISSÃO ACEITO NÍVEL Baú do chefe e parenteses I 1068 01 34566069 5 Diamante e Areia 1069 3 Infixa para Posfixa 1077 7 LEXSIM Avaliador Léxico e Sintático 1083 1 Eu Posso Adivinhar Estrutura de Dados 1106 2 Jogo da Forca 1340 4 Fila do Pânico 1522 5 Fila do Banco 1524 5 SBC 1533 5 Fila 1633 6 Fila do SUS 2460 100 Fibonacci Ki 2506 100 Menor da pilha 2839 100 Aquele tire de pilha 2929 100 Lista de Exercícios 02 listas F Privacidade Termos e Condições FAQs Status Contato Pesquisar 1069 def countdiamondsline stack count 0 for char in line if char stackappendchar elif char and stack and stack1 stackpop count 1 return count Ler o número de casos de teste numtestcases intinput resultados Processar cada caso de teste for in rangenumtestcases linha input diamonds countdiamondslinha resultadosappenddiamonds Imprimir os resultados for diamonds in resultados printdiamonds 1077 Função para verificar se um caractere é um operador def ehoperadorcaractere operadores if caractere in operadores return True return False Função para verificar a precedência de um operador def precedenciaoperadoroperador precedencia 1 1 2 2 3 return precedenciagetoperador 0 Função para converter a expressão infixada em posfixada def converterposfixadaexpressao pilha posfixada for caractere in expressao if caractereisalnum posfixada caractere elif caractere pilhaappendcaractere elif caractere while pilha and pilha1 posfixada pilhapop pilhapop Remove o da pilha elif ehoperadorcaractere while pilha and pilha1 and precedenciaoperadorcaractere precedenciaoperadorpilha1 posfixada pilhapop pilhaappendcaractere while pilha posfixada pilhapop return posfixada Leitura do número de casos de teste n intinput Processamento de cada caso de teste for in rangen expressao input posfixada converterposfixadaexpressao printposfixada 1083 import re import sys def isvalidexpressionexpression Verifica se a expressão contém apenas caracteres válidos if not rematchrazAZ09 expression return False Lexical Error Verifica se os parênteses estão balanceados stack for char in expression if char stackappendchar elif char if not stack return False Syntax Error stackpop if stack return False Syntax Error Verifica se os operadores estão sendo usados corretamente operators set prevchar None for char in expression if char in operators and prevchar is None or prevchar in operators or prevchar return False Syntax Error prevchar char return True def topostfixexpression Converte a expressão para a forma posfixa precedence 6 5 5 4 4 3 3 3 3 2 1 stack postfixexpression for char in expression if charisalnum postfixexpression char elif char stackappendchar elif char while stack and stack1 postfixexpression stackpop stackpop else while stack and stack1 and precedencechar precedencestack1 postfixexpression stackpop stackappendchar while stack postfixexpression stackpop return postfixexpression for expression in sysstdin expression expressionstrip isvalid errormessage isvalidexpressionexpression if isvalid postfixexpression topostfixexpression printpostfixexpression else printerrormessage 1110 from collections import deque while True n intinput if n 0 break deck dequerange1 n 1 cartasdescartadas while lendeck 2 Descarta a carta do topo cartadescartada deckpopleft cartasdescartadasappendcartadescartada Move a nova carta do topo para o final novacartatopo deckpopleft deckappendnovacartatopo Imprime os resultados printDiscarded cards joinmapstr cartasdescartadas printRemaining card deck0 1340 from queue import Queue LifoQueue PriorityQueue def main while True try n intinput except EOFError break queueN stackN pqueue True True True queue Queue stack LifoQueue priorityqueue PriorityQueue for in rangen comando x mapint inputsplit if comando 1 priorityqueueputx x stackputx queueputx else if not stackempty and stackget x stackN False if not queueempty and queueget x queueN False if not priorityqueueempty and priorityqueueget1 x pqueue False if not stackN or queueN or pqueue printimpossible elif stackN and pqueue or stackN and queueN or pqueue and queueN printnot sure elif pqueue printpriority queue elif queueN printqueue elif stackN printstack if name main main 1522 m n 0 pilha 0 for i in range102 for j in range3 def funcaoa b c s stra strb strc if a b and b c and c n ms 1 return True x mgets 0 if x 0 return x 1 if a n and pilha0a 3 0 and funcaoa 1 b c ms 1 return True if b n and pilha1b 3 0 and funcaoa b 1 c ms 1 return True if c n and pilha2c 3 0 and funcaoa b c 1 ms 1 return True if a n and b n and pilha0a pilha1b 3 0 and funcaoa 1 b 1 c ms 1 return True if a n and c n and pilha0a pilha2c 3 0 and funcaoa 1 b c 1 ms 1 return True if b n and c n and pilha1b pilha2c 3 0 and funcaoa b 1 c 1 ms 1 return True if a n and b n and c n and pilha0a pilha1b pilha2c 3 0 and funcaoa 1 b 1 c 1 ms 1 return True ms 2 return False while True n intinput if not n break for i in rangen values listmapint inputsplit for j in range3 pilhaji valuesj if funcao000 print1 else print0 mclear 1524 def comparea b return b a while True try n k mapint inputsplit aux 0 n arr 0 n aux0 0 arr0 0 inputvalues inputsplit for i in range1 n auxi intinputvaluesi1 arri auxi auxi 1 arrsortreverseTrue sum 0 for i in rangek 1 n sum arri printsum except EOFError break 1537 fat 0 100002 n 0 fat3 1 for i in range4 100001 fati i fati 1 1000000009 while True n intinput if not n break printfatn 1633 from queue import PriorityQueue class Processo def initself selft 0 selfc 0 class Comp def initself p selfp p def ltself other return selfpc otherpc def sortAlgp1 p2 return p1t p2t while True try n intinput if n 0 break espera 0 tempoExec 0 processos for i in rangen p Processo pt pc mapint inputsplit if i 0 or pt tempoExec tempoExec pt processosappendp processossortkeylambda x xt f PriorityQueue for p in processos if pt tempoExec q fgetp if qt tempoExec espera tempoExec qt else tempoExec qt tempoExec qc fputCompp while not fempty q fgetp if qt tempoExec espera tempoExec qt else tempoExec qt tempoExec qc printespera except EOFError break 2460 class Pessoa def initself selfnumero 0 selfposicao 0 qtsPessoas intinput qtsPessoasSairam 0 fila Pessoa for in range51000 idsPessoas inputsplit for i in rangeqtsPessoas idPessoa intidsPessoasi filainumero idPessoa filaidPessoaposicao i qtsPessoasSairam intinput idsPessoasSairam inputsplit for i in rangeqtsPessoasSairam idPessoa intidsPessoasSairami filafilaidPessoaposicaonumero 0 primEspaco False for i in rangeqtsPessoas if filainumero if primEspaco and i qtsPessoas print end primEspaco True printfilainumero end print 2506 while True try n intinput except EOFError break ans 0 tempototal 420 for in rangen hora minuto critico mapint inputsplit while tempototal hora 60 minuto tempototal 30 if tempototal hora 60 minuto critico ans 1 tempototal 30 printans 2893 T intinput resultslist Criar a lista antes do loop for in rangeT k N mapint inputsplit seq i for i in rangek for i in rangek N nextelement sumseqk 1000007 seqappendnextelement result seqN1 printresult resultslistappendresult Adicionar o resultado à lista 2929 n intinput words for in rangen word input wordsappendword wordssortkeylambda x xlower x for word in words printword 3136 N intinput stack memory 0 100 results for in rangeN command input if commandstartswithpush value commandsplit1 if valuestartswithR pos intvalue1 stackappendmemorypos else stackappendintvalue elif commandstartswithpop pos intcommandsplit11 memorypos stackpop elif command add a stackpop b stackpop stackappenda b elif command mul a stackpop b stackpop stackappenda b elif command div a stackpop b stackpop stackappendb a elif command sub a stackpop b stackpop stackappendb a elif command print resultsappendstackpop for result in results printresult
Send your question to AI and receive an answer instantly
Recommended for you
4
Lista de Exercícios Estrutura de Dados - Vetor de Consultas e Rotação
Estrutura de Dados
IFCE
9
Implementacao TAD Matriz em C++ Orientado a Objetos - Lista de Exercicios
Estrutura de Dados
IFCE
8
Analise Empirica de Algoritmos de Ordenacao em Listas Duplamente Encadeadas
Estrutura de Dados
IFCE
7
Analise Comparativa de Algoritmos de Ordenacao - BubbleSort InsertionSort SelectionSort MergeSort e QuickSort
Estrutura de Dados
IFCE
1
Lista de Exercícios de Programação - Listas Filas e Pilhas em C Java Python Ruby
Estrutura de Dados
IFCE
9
Implementação de ForwardList em C++: Concatenação, Remoção e Clonagem
Estrutura de Dados
IFCE
5
Lista de Exercícios Recursão em C - Estrutura de Dados e Algoritmos
Estrutura de Dados
IFCE
7
Projeto 01 Matrizes Esparsas em C - Implementacao de TAD e Operacoes
Estrutura de Dados
IFCE
3
Simulação de Fila de Decolagem e Operações com Pilhas em C
Estrutura de Dados
IFCE
25
Calculando-Altura-e-Numero-de-Nos-em-Arvore-Binaria
Estrutura de Dados
IFCE
Preview text
PROGRESSO PROBLEMA SUBMISSÃO ACEITO NÍVEL Baú do chefe e parenteses I 1068 01 34566069 5 Diamante e Areia 1069 3 Infixa para Posfixa 1077 7 LEXSIM Avaliador Léxico e Sintático 1083 1 Eu Posso Adivinhar Estrutura de Dados 1106 2 Jogo da Forca 1340 4 Fila do Pânico 1522 5 Fila do Banco 1524 5 SBC 1533 5 Fila 1633 6 Fila do SUS 2460 100 Fibonacci Ki 2506 100 Menor da pilha 2839 100 Aquele tire de pilha 2929 100 Lista de Exercícios 02 listas F Privacidade Termos e Condições FAQs Status Contato Pesquisar 1069 def countdiamondsline stack count 0 for char in line if char stackappendchar elif char and stack and stack1 stackpop count 1 return count Ler o número de casos de teste numtestcases intinput resultados Processar cada caso de teste for in rangenumtestcases linha input diamonds countdiamondslinha resultadosappenddiamonds Imprimir os resultados for diamonds in resultados printdiamonds 1077 Função para verificar se um caractere é um operador def ehoperadorcaractere operadores if caractere in operadores return True return False Função para verificar a precedência de um operador def precedenciaoperadoroperador precedencia 1 1 2 2 3 return precedenciagetoperador 0 Função para converter a expressão infixada em posfixada def converterposfixadaexpressao pilha posfixada for caractere in expressao if caractereisalnum posfixada caractere elif caractere pilhaappendcaractere elif caractere while pilha and pilha1 posfixada pilhapop pilhapop Remove o da pilha elif ehoperadorcaractere while pilha and pilha1 and precedenciaoperadorcaractere precedenciaoperadorpilha1 posfixada pilhapop pilhaappendcaractere while pilha posfixada pilhapop return posfixada Leitura do número de casos de teste n intinput Processamento de cada caso de teste for in rangen expressao input posfixada converterposfixadaexpressao printposfixada 1083 import re import sys def isvalidexpressionexpression Verifica se a expressão contém apenas caracteres válidos if not rematchrazAZ09 expression return False Lexical Error Verifica se os parênteses estão balanceados stack for char in expression if char stackappendchar elif char if not stack return False Syntax Error stackpop if stack return False Syntax Error Verifica se os operadores estão sendo usados corretamente operators set prevchar None for char in expression if char in operators and prevchar is None or prevchar in operators or prevchar return False Syntax Error prevchar char return True def topostfixexpression Converte a expressão para a forma posfixa precedence 6 5 5 4 4 3 3 3 3 2 1 stack postfixexpression for char in expression if charisalnum postfixexpression char elif char stackappendchar elif char while stack and stack1 postfixexpression stackpop stackpop else while stack and stack1 and precedencechar precedencestack1 postfixexpression stackpop stackappendchar while stack postfixexpression stackpop return postfixexpression for expression in sysstdin expression expressionstrip isvalid errormessage isvalidexpressionexpression if isvalid postfixexpression topostfixexpression printpostfixexpression else printerrormessage 1110 from collections import deque while True n intinput if n 0 break deck dequerange1 n 1 cartasdescartadas while lendeck 2 Descarta a carta do topo cartadescartada deckpopleft cartasdescartadasappendcartadescartada Move a nova carta do topo para o final novacartatopo deckpopleft deckappendnovacartatopo Imprime os resultados printDiscarded cards joinmapstr cartasdescartadas printRemaining card deck0 1340 from queue import Queue LifoQueue PriorityQueue def main while True try n intinput except EOFError break queueN stackN pqueue True True True queue Queue stack LifoQueue priorityqueue PriorityQueue for in rangen comando x mapint inputsplit if comando 1 priorityqueueputx x stackputx queueputx else if not stackempty and stackget x stackN False if not queueempty and queueget x queueN False if not priorityqueueempty and priorityqueueget1 x pqueue False if not stackN or queueN or pqueue printimpossible elif stackN and pqueue or stackN and queueN or pqueue and queueN printnot sure elif pqueue printpriority queue elif queueN printqueue elif stackN printstack if name main main 1522 m n 0 pilha 0 for i in range102 for j in range3 def funcaoa b c s stra strb strc if a b and b c and c n ms 1 return True x mgets 0 if x 0 return x 1 if a n and pilha0a 3 0 and funcaoa 1 b c ms 1 return True if b n and pilha1b 3 0 and funcaoa b 1 c ms 1 return True if c n and pilha2c 3 0 and funcaoa b c 1 ms 1 return True if a n and b n and pilha0a pilha1b 3 0 and funcaoa 1 b 1 c ms 1 return True if a n and c n and pilha0a pilha2c 3 0 and funcaoa 1 b c 1 ms 1 return True if b n and c n and pilha1b pilha2c 3 0 and funcaoa b 1 c 1 ms 1 return True if a n and b n and c n and pilha0a pilha1b pilha2c 3 0 and funcaoa 1 b 1 c 1 ms 1 return True ms 2 return False while True n intinput if not n break for i in rangen values listmapint inputsplit for j in range3 pilhaji valuesj if funcao000 print1 else print0 mclear 1524 def comparea b return b a while True try n k mapint inputsplit aux 0 n arr 0 n aux0 0 arr0 0 inputvalues inputsplit for i in range1 n auxi intinputvaluesi1 arri auxi auxi 1 arrsortreverseTrue sum 0 for i in rangek 1 n sum arri printsum except EOFError break 1537 fat 0 100002 n 0 fat3 1 for i in range4 100001 fati i fati 1 1000000009 while True n intinput if not n break printfatn 1633 from queue import PriorityQueue class Processo def initself selft 0 selfc 0 class Comp def initself p selfp p def ltself other return selfpc otherpc def sortAlgp1 p2 return p1t p2t while True try n intinput if n 0 break espera 0 tempoExec 0 processos for i in rangen p Processo pt pc mapint inputsplit if i 0 or pt tempoExec tempoExec pt processosappendp processossortkeylambda x xt f PriorityQueue for p in processos if pt tempoExec q fgetp if qt tempoExec espera tempoExec qt else tempoExec qt tempoExec qc fputCompp while not fempty q fgetp if qt tempoExec espera tempoExec qt else tempoExec qt tempoExec qc printespera except EOFError break 2460 class Pessoa def initself selfnumero 0 selfposicao 0 qtsPessoas intinput qtsPessoasSairam 0 fila Pessoa for in range51000 idsPessoas inputsplit for i in rangeqtsPessoas idPessoa intidsPessoasi filainumero idPessoa filaidPessoaposicao i qtsPessoasSairam intinput idsPessoasSairam inputsplit for i in rangeqtsPessoasSairam idPessoa intidsPessoasSairami filafilaidPessoaposicaonumero 0 primEspaco False for i in rangeqtsPessoas if filainumero if primEspaco and i qtsPessoas print end primEspaco True printfilainumero end print 2506 while True try n intinput except EOFError break ans 0 tempototal 420 for in rangen hora minuto critico mapint inputsplit while tempototal hora 60 minuto tempototal 30 if tempototal hora 60 minuto critico ans 1 tempototal 30 printans 2893 T intinput resultslist Criar a lista antes do loop for in rangeT k N mapint inputsplit seq i for i in rangek for i in rangek N nextelement sumseqk 1000007 seqappendnextelement result seqN1 printresult resultslistappendresult Adicionar o resultado à lista 2929 n intinput words for in rangen word input wordsappendword wordssortkeylambda x xlower x for word in words printword 3136 N intinput stack memory 0 100 results for in rangeN command input if commandstartswithpush value commandsplit1 if valuestartswithR pos intvalue1 stackappendmemorypos else stackappendintvalue elif commandstartswithpop pos intcommandsplit11 memorypos stackpop elif command add a stackpop b stackpop stackappenda b elif command mul a stackpop b stackpop stackappenda b elif command div a stackpop b stackpop stackappendb a elif command sub a stackpop b stackpop stackappendb a elif command print resultsappendstackpop for result in results printresult