TOPIC
PROBLEM 1171 - URI Fórum 1.0
This topic was solved and cannot recieve new replies.
-
rsgoncalves0 replied 7 years ago
como faço para evitar duplicação na saída?
#include <iostream> using namespace std; int Vnum1[2000]; int z=0; int i=0; int y=0; int x=0; int w=0; int cc[2000]; int main(int argc, char** argv) { while(cin>>Vnum1[z++]){ if(Vnum1[i]<1&&Vnum1[i]>2000){ break; } } for(x=0;x<z;x++){ for(w=0;w<z;w++){ if ((Vnum1[x]==Vnum1[w])){ cc[x]=cc[x] +1; } } } for(y=0;y<z;y++){ cout<<" "<<Vnum1[y]<<" aparece "<<cc[y]<<" vez(es)"<<endl; } return 0; }
eu coloco na entrada:
7 8 10 8 260 4 10 10
e sai:
7 aparece 1 vez(es) 8 aparece 2 vez(es) 10 aparece 3 vez(es) 8 aparece 2 vez(es) 260 aparece 1 vez(es) 4 aparece 1 vez(es) 10 aparece 3 vez(es) 10 aparece 3 vez(es)
-
gmarini replied 7 years ago
MODComo eu disse antes, a entrada só contém um caso de teste, que é representado por uma única variável, a qual vale "7" no caso do exemplo do portal. Você está lendo um número ilimitado de números, o que está causando o Runtime:
while(cin>>Vnum1[z++])
Para fazer a entrada de dados nesse problema, você pode utilizar linhas como essas:
cin >> n; for(int i=0;i<n;i++){ cin >> Vnum1[i]; }
Fazendo isso, você deve trocar em todos os outros laços a variável "z" por "n".
-
wadjlima replied 7 years ago
Alguém pode me ajudar do Porque o código abaixo estar dando resposta errada?
include
int main () {
int v[2000]; int i, j, k, N, X;
scanf("%d", &N);
for (i=0; i<2000; i++){ v[i] = 0; } j = 0; while (j<N){ scanf("%d", &X); v[X] = v[X]++; j = j++; } k = 0; for (j=0; j<2000; j++){ if (v[j] != 0){ k = j+1; printf ("%d aparece %d vez(es)\n", k, v[j]); } }
return 0; }
-
rsgoncalves0 replied 7 years ago
Resolvi o problema mas agora está dando "Runtime error" (antes tbm dava)
#include <iostream> #include <algorithm> using namespace std; int Vnum1[2000]; int cc[20]; int z=0; int i=0; int main(int argc, char** argv) { while(cin>>Vnum1[z++]){ } for(int sort=0; sort<z;sort++){ if(Vnum1[sort-1]>Vnum1[sort]){ if (Vnum1[sort]==0)break; swap(Vnum1[sort-1],Vnum1[sort]); sort=0; } } for(int x=0;x<z;x++){ for(int w=0;w<z;w++){ if (Vnum1[x]==Vnum1[w]){ cc[x]=cc[x] +1; } } } for(int y=0;y<z;y++){ if(Vnum1[y]==0||Vnum1[y]>2000) return 0; if(Vnum1[y]!=Vnum1[y+1]) cout<<Vnum1[y]<<" aparece "<<cc[y]<<" vez(es)"<<endl; } return 0; }
-
gmarini replied 7 years ago
MODEsse problema não é com entrada EOF.
O número 7 que você processou no seu código é o número de valores X que devem ser lidos. Além disso, esse é um problema típico de implementação com Counting Sort. Dê uma olhada no link e tente dar uma arrumada no seu código. Qualquer dúvida adicional, pode perguntar.
-
vcortez replied 8 years ago
Tá dando wrong answer 100% e eu não sei porque. De todos os testes que eu fiz com o Toolkit deu perfeitamente certo. Agradeço previamente a quem tentar me ajudar.
#include <stdio.h> int main() { /** * Escreva a sua solução aqui * Code your solution here * Escriba su solución aquí */ int count,i; int lista[2001] = {0}; scanf("%d",&count); for (i = 0; i < count; i += 1){ int numero; scanf("%d",&numero); lista[numero] += 1; } int o; for (o = 0; o < 2000; o = o + 1){ if (lista[o] > 0){ printf("%d aparece %d vez(es)\n",o,lista[o]); } } return 0; }
-
joaowilian replied 8 years ago
Estou recebendo Time limit exceeded, alguém poderia me ajudar?
x = int(input('')) distintos = [] numeros = [] cont = 0 while x > 0: y = int(input('')) numeros.append(y) if y not in distintos: distintos.append(y) x -= 1 distintos.sort() for i in distintos: for j in numeros: if i == j: cont += 1 print('%d aparece %d vez(es)' %(i, cont)) cont = 0
-
bjbj1991 replied 8 years ago
Hello i got run time error plz help me fixed it. thanks!\
#include <iostream> #include <algorithm> using namespace std; void sapxep(int a[],int n) { for(int i=1;i<n;i++) { for(int j=0;j<n-i;j++) { if(a[j]>a[j+1]) swap(a[j],a[j+1]); } } } int main(void) { int a[2001]={0},b[2001],c[2001]; int n; cin >> n; for(int i=0;i<n;i++) { cin >>a[i]; } sapxep(a,n); int k=1; int dem=1; for(int i=0;i<n;i++) { if(a[i]==a[i+1]) { dem++; } else{ b[k]=a[i]; c[k]=dem; k++; dem=1; } } for(int i=1;i<k;i++) { cout << b[i] << " aparece " << c[i] << " vez(es)" <<endl; } return 0; }
-
cgreche replied 8 years ago
Olá Neilor, tudo bem?
Também tenho uma sugestão: reedite esse problema. Não faz sentido (ou faz?) esse negócio de "aparecerá no máximo 20 vezes" já que no próprio Toolkit é possível fazer um valor aparecer mais que 20 vezes. Na minha opinião, isso só confunde o usuário.
Obrigado.
-
jdamasio0 replied 9 years ago
Obrigado, meu caro! Realmente foi um vacilo bobo, foi burrice duvidar do juiz! =D
-
mtreviso replied 9 years ago
O range() do Python usa intervalo aberto partindo do 0. Nesse caso você declarou uma lista de 0 a 1999. Basta trocar para:
lista = [0 for i in range(2001)]
Valeu!
-
jdamasio0 replied 9 years ago
Opa, pessoal.
Tenho ficado um pouco chateado com questões que em Python dão Runtime Error, e em outras linguagens (o mesmo algoritmo) passa tranquilo. Aqui não foi diferente. Alguém consegue enxergar o RE nesse código?
Resolvido. Código estava errado, vide resposta abaixo.
-
Jhonatan0 replied 9 years ago
Alguém poderia me informar oque há de errado no meu código, estou recebendo Wrong Anser, e não fala quantos % está errado. Obrigado.
#include <stdio.h> #include <iostream> #include <string.h> using namespace std; int main(){ int i,n,vetor[2001],numero; memset(vetor,0,(sizeof(int)*2001)); cin >> n; for(i=0;i<n;i++){ cin >> numero; vetor[numero]++; } for(i=0;i<2000;i++){ if(vetor[i]>0) cout << i << " aparece " << vetor[i] << " vez(es)\n"; } return 0; }
-
ggroth replied 9 years ago
I'm not sure, but I guess the number N can be greater than 2000. Each value is between 1 and 2000. Try to declare the array with 5000 or 10000 positions. Moreover, your sorting algorithm is slow. Maybe you'll get TLE.
-
jtamimi replied 9 years ago
edited but still wrong answer :(
#include <iostream> using namespace std; int main() { int a[2000]; int r; int k=0; int temp; cin >>r; for(int i=0;i<r;i++) { cin>>a[i]; } for(int i=0;i<r;i++){ for(int j=0;j<r-1;j++){ if(a[j]>a[j+1]){ temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } for(int i=0; i<r; i++) { k=0; for(int j=0; j<r; j++) { if (a[i] == a[j]) k++; } if(k<=20) if (a[i] != a[i+1]) cout <<a[i] <<" aparece "<<k <<" vez(es)"<<endl; } return 0; } }
-
ggroth replied 9 years ago
This is the output of your code for the sample input:
8 aparece 15 vez(es) 8 aparece 15 vez(es) 10 aparece 15 vez(es) 260 aparece 15 vez(es)
You're printing the number 8 twice and you are not printing the number 4. Furthermore, the number of times each number appears is not the same for all (15).
-
jtamimi replied 9 years ago
Can any one help me i have to submit the answer of this problem correctly to have a bonus on the course :( ...
i tried this code on the visual studio and its worked ,, but after submitting it give wrong answer :( please help
My code :
#include <iostream> using namespace std; int main() { int a[2000]; int r; int x=0; int temp; cin >>r; for(int i=0;i<r;i++) { cin>>a[i]; } for(int i=0; i<r; i++) { for(int j=0; j<r; j++) { if (a[i] == a[j]) x++; } } for(int i=0;i<r;i++){ for(int j=0;j<r-1;j++){ temp=j; if(a[j]>a[j+1]){ temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } if (a[i] != a[i+1]) cout <<a[i] <<" aparece "<<x <<" vez(es)"<<endl; } return 0; }
-
erodrigues replied on Mar 13 2014
MODNo problema diz que cada número pode aparecer até 20 vezes, e os valores lidos serão entre 1 e 2000, a partir disso podemos deduzir que o primeiro valor poderá valer até 20 * 2000. Então, laços como esse não estão certos já que o tamanho do seu vetor é só de 2000:
for (i=0; i<x; i++){ scanf ("%d", &y[i]); }
-
Alex15 replied on Mar 9 2014
POR FAVOR, ALGUÉM DIZ O ERRO. O PROGRAMA FUNCIONA DE BOA, EU FIZ VÁRIOS TESTES,MAS ESTÁ DANDO "Wrong Answer"
#include <stdio.h> #include <algorithm> using namespace std; int main () { int x, i, j, y[2000], d[2000], k, m, a, b; scanf ("%d", &x); for (m=0; m<=x; m++){ d[m]=0; } for (i=0; i<x; i++){ scanf ("%d", &y[i]); } for (a=0; a<x; a++){ for (b=0; b<x; b++){ if (y[a]>y[b] && b>a){ swap (y[a],y[b]); } } } for (j=0; j<x; j++){ for (k=0; k<x; k++){ if (y[j]==y[k]){ d[j]++; } } if (y[j]!=y[j-1]){ printf ("%d aparece %d vez(es)\n", y[j], d[j]); } } }