TÓPICO
PROBLEM 1258 - URI Fórum 1.0
Este tópico foi resolvido e não pode receber novas respostas.
-
al1003 respondido 7 years ago
Boa noite galera... meu código está apresentando "Presentation Error" quando submeto no URI, porém todos os casos de teste estão batendo.. e já conferi o Output, pulei uma linha entre 2 casos de teste. Alguem pode me ajudar?
accepted
-
mmelo3 respondido 8 years ago
Nunca use fflush aqui no uri. Sempre que quiser limpar o buffer use getchar(). Retire o "&" do seu "gets(&turma[i].nome);". Faça essas alterações e você receberá accepeted.
-
sma_umg respondido 8 years ago
Estou recebento TL, mas não consigo mais melhorar o código, alguém pode dar uma dica?
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct uniforme { char cor[9], tam, nome[51]; } Camisa; int cpr(const void * a, const void * b) { Camisa *A = (Camisa*)a; Camisa *B = (Camisa*)b; int c = A->cor[0] - B->cor[0]; if(c == 0) { c = B->tam - A->tam; if(c == 0) return strcmp(A->nome,B->nome); return (c); } return (c); } int main () { int N, i = 0; Camisa turma[60]; scanf("%d", &N); while (N != 0) { if(i>0) printf("\n"); for (i=0; i<N; i++) { fflush(stdin); gets(&turma[i].nome); //scanf("%[ -~]s", &turma[i].nome); scanf("%s %c", &turma[i].cor, &turma[i].tam); } qsort(turma,N,sizeof(Camisa),cpr); for(i=0; i<N; i++) printf("%s %c %s\n", turma[i].cor, turma[i].tam, turma[i].nome); scanf("%d", &N); } return 0; }
-
rsantana4 respondido 7 years ago
private static class Shirt implements Comparable<Shirt> { private final String NAME; private final String COLOR; private final String SIZE; public Shirt(String name, String color, String size) { this.NAME = name; this.COLOR = color; this.SIZE = size; } @Override public int compareTo(Shirt o) { int i = COLOR.compareTo(o.COLOR); if (i != 0) { return i; } i = o.SIZE.compareTo(SIZE); return i == 0 ? NAME.compareToIgnoreCase(o.NAME) : i; } @Override public String toString() { return COLOR + " " + SIZE + " " + NAME; } } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader( new InputStreamReader(System.in)); boolean breakLine = false; while (true) { String input = br.readLine(); if (input.equals("0")) { break; } if (breakLine) { System.out.println(); } int testCases = Integer.parseInt(input); List<Shirt> shirts = new ArrayList(); for (int i = 0; i < testCases; i++) { String name = br.readLine(); String[] shirt = br.readLine().split(" "); shirts.add(new Shirt(name, shirt[0], shirt[1])); } Collections.sort(shirts); for (Shirt s : shirts) { System.out.println(s); } breakLine = true; } }
WA 10%. O que há de errado??
-
cferreira24 respondido 7 years ago
import java.util.Scanner; import java.util.Arrays;
public class Main {
public static void main(String[] args) { Scanner entrada = new Scanner(System.in); int rodada=Integer.parseInt(entrada.nextLine()); String[] lista=new String [rodada]; int cont=0; while(rodada!=0){ for(int i =0 ; i < rodada ; i++){ String nome =entrada.nextLine(); String CorETamanho =entrada.nextLine(); String dado=CorETamanho+" "+nome; lista[i]=dado; } String [] novaLista=ordena(lista); Arrays.sort(novaLista); for(int i=0 ;i < rodada; i++){ char [] lista2 =novaLista[i].toCharArray(); if(lista2[7]=='a'){ lista2[7]='P'; String dado=""; for(int x =0 ; x<lista2.length;x++){ dado+=lista2[x]; } char []x =dado.toCharArray(); String dado2=""; if(x[0]=='v'){ x[7]='o'; for(int n=0 ; n < x.length ; n++){ dado2+=x[n]; } System.out.println(dado2); } else{ System.out.println(dado); } cont++; } else if(lista2[7]=='b'){ lista2[7]='M'; String dado=""; for(int x =0 ; x<lista2.length;x++){ dado+=lista2[x]; } char []x =dado.toCharArray(); String dado2=""; if(x[0]=='v'){ x[7]='o'; for(int n=0 ; n < x.length ; n++){ dado2+=x[n]; } System.out.println(dado2); } else{ System.out.println(dado); } cont++; } else { lista2[7]='G'; String dado=""; for(int x =0 ; x<lista2.length;x++){ dado+=lista2[x]; } char []x =dado.toCharArray(); String dado2=""; if(x[0]=='v'){ x[7]='o'; for(int n=0 ; n < x.length ; n++){ dado2+=x[n]; } System.out.println(dado2); }else{ System.out.println(dado); } cont++; } }// final do segundo for if(cont==rodada){ rodada=Integer.parseInt(entrada.nextLine()); System.out.println(""); cont=0; lista=null; lista=new String[rodada]; } }// while } public static String []ordena(String []lista){ String []listaNova=lista; for(int i=0 ; i <lista.length ; i++){ char [] listaDeChar=listaNova[i].toCharArray(); if(listaDeChar[7]=='P'){ listaDeChar[7]='a'; String dado=""; for(int k =0 ; k < listaDeChar.length ; k++){ dado+=listaDeChar[k]; } listaNova[i]=dado; } else if(listaDeChar[7]=='M'){ listaDeChar[7]='b'; String dado=""; for(int k =0 ; k < listaDeChar.length ; k++){ dado+=listaDeChar[k]; } listaNova[i]=dado; } else { listaDeChar[7]='c'; String dado=""; for(int k =0 ; k < listaDeChar.length ; k++){ dado+=listaDeChar[k]; } listaNova[i]=dado; } } return listaNova; }// final do método
}// final da classe
-
mmelo3 respondido 8 years ago
Não consegui encontrar erro no seu código, mas se serve de ajuda, resolvi essa questão criando uma struct com as características de cada camiseta e ordenei usando o sort da algorithm.
-
nfuchs respondido 8 years ago
Alguém pode me falar alguma condição que esse código dá errado?
#include <stdio.h> #include <stdlib.h> struct arvore_bin { struct no_bin * raiz; }; struct no_bin { char tam; char * nome; struct no_bin * esq; struct no_bin * dir; }; struct no_bin * cria_no_bin(char * nome, char tam) { struct no_bin * aux = (struct no_bin *) malloc(sizeof(struct no_bin)); if(aux) { aux->tam = tam; aux->nome = nome; aux->esq = NULL; aux->dir = NULL; } return aux; } void inicia_arvore(struct arvore_bin *a) { a->raiz = NULL; } int arvore_vazia(struct arvore_bin a) { return a.raiz == NULL; } void insere_aux(struct no_bin * novo, struct no_bin * atual) { if(novo->tam < atual->tam || strcoll(novo->nome, atual->nome) >= 0) { if(atual->dir == NULL) atual->dir = novo; else insere_aux(novo, atual->dir); } else { if(atual->esq == NULL) atual->esq = novo; else insere_aux(novo, atual->esq); } } void insere(char * nome, char tam, struct arvore_bin *a) { struct no_bin * novo = cria_no_bin(nome, tam); if(novo) if(arvore_vazia(*a)) a->raiz = novo; else insere_aux(novo, a->raiz); else printf("\nNão foi possível alocar memoria\n\n"); } void mostra_em_ordem_aux(struct no_bin *atual, char * cor) { if(atual) { mostra_em_ordem_aux(atual->esq, cor); printf("%s %c %s\n", cor, atual->tam, atual->nome); mostra_em_ordem_aux(atual->dir, cor); } } void mostra_em_ordem(struct arvore_bin *a, char * cor) { if(arvore_vazia(*a)) printf("Arvore vazia"); else mostra_em_ordem_aux(a->raiz, cor); } void flush_in(){ int ch; while( (ch = fgetc(stdin)) != EOF && ch != '\n' ){} } int main(int argc, char*argv[]) { struct arvore_bin branco, vermelho; int s, i; char tam; scanf("%d", &s); while(s) { inicia_arvore(&branco); inicia_arvore(&vermelho); char nome[s][51]; char cor_aux[9]; for(i = 0; i < s; i++) { flush_in(); scanf("%[^\n]s", nome[i]); flush_in(); scanf("%s %c", cor_aux, &tam); insere(nome[i], tam, !strcmp("branco", cor_aux)? &branco : &vermelho); } if(!arvore_vazia(branco)) mostra_em_ordem(&branco, "branco"); if(!arvore_vazia(vermelho)) mostra_em_ordem(&vermelho, "vermelho"); scanf("%d", &s); printf("\n"); } return 0; }
-
jmachado2 respondido 9 years ago
Me ajudem a descobrir por que recebo Presentation Error
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <iostream> #include <string> #include <vector> using namespace std; int compara(string linha1, string linha2){ int s1 = linha1.find_first_of(' '); int s2 = s1+2; int s3 = linha2.find_first_of(' '); int s4 = s3+2; string cor1=linha1.substr(0,s1); string cor2=linha2.substr(0,s3); string tamanho1=linha1.substr(s1+1,1); string tamanho2=linha2.substr(s3+1,1); string nome1=linha1.substr(s2+1,linha1.size()); string nome2=linha2.substr(s4+1,linha2.size()); if (cor1.compare(cor2)>0){ return 1; } else if (cor1.compare(cor2)<0){ return 0; } if (tamanho1.compare(tamanho2)<0){ return 1; } else if (tamanho1.compare(tamanho2)>0){ return 0; } if (nome1.compare(nome2)>0){ return 1; } return 0; } void ordena_vetores(vector <string> &vet, int n){ for (int i=0; i<n; i++){ for (int j=i+1; j<n; j++){ if (compara(vet[i],vet[j])){ string aux = ""+vet[i]; vet[i]=""+vet[j]; vet[j]=""+aux; } } } } void le_turma(int n){ int t=0; vector <string> vet(n); vector <string> vet2(n); while (t<n){ getline(cin,vet[t]); getline(cin,vet2[t]); t++; } for ( int i=0; i<n; i++){ vet[i]=vet2[i]+" "+vet[i]; } ordena_vetores(vet,n); for (int i=0;i<n;i++){ cout << vet[i] << "\n"; } } int main (void){ int n=-1; int k=0; while(1){ cin>>n; if (n==0){ return 0; } cin.ignore(); le_turma(n); cout<<"\n"; k++; } return 0; }
-
aalves8 respondido 9 years ago
Estou recebendo Wrong Answer 100% nesse exercício mas não consigo entender o motivo. Até aumentei o tamanho do nome, dou espaço entre casos de teste mas nada...
Resolvido.
EDIT:
Esse exercício está estranho, só consegui passar quando troquei tudo para e utilizei iostream para E/S.
-
cdmpadilha respondido 9 years ago
Alguém sabe me dizer um caso de teste que falhe ? Estou recebendo 20%
Resolvido