TOPIC
PROBLEM 1196 - URI Fórum 1.0
This topic was solved and cannot recieve new replies.
-
Gustavo Marini replied 4 years ago
MODTrês coisas. Primeiro que você precisa criar um vetor de caracteres, e não apenas um "char c;". Então defina assim:
char c[10000];
Acredito que 10000 já seja um tamanho significante para esta questão, mas se precisar de mais, pode aumentar.
A segunda coisa é do "fflush(stdin);", acredito que o portal não aceite essa função e, também, acho que ela não é necessária neste problema.
Além disso, você precisa percorrer toda a string (frase) de entrada para fazer as verificações de letras. Faça isso com um laço "for":
for(i=0;i<strlen(c);i++){ if(c[i]=='1') c[i]='`'; else if(c[i]=='2') c[i]='1'; ... // e assim por diante. }
-
Antonio "Juvenil" Carlos replied 4 years ago
Olá, estou resolvendo esse problema mas estou recebendo Wrong Answer 100% no URI :/
#include <stdio.h> #include <stdlib.h> int main() { char c; while(gets(c)){ fflush(stdin); if (c==' ') printf("%c",c); else if (c=='1') printf("`"); else if (c=='2') printf("1"); else if (c=='3') printf("2"); else if (c=='4') printf("3"); else if (c=='5') printf("4"); else if (c=='6') printf("5"); else if (c=='7') printf("6"); else if (c=='8') printf("7"); else if (c=='9') printf("8");
E assim por adiante até o caracter / CREIO que o problema esteja na leitura
-
Richard replied 4 years ago
#include <iostream> #include <string> using namespace std; int main(){ string str1("1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./"); string str2; /** Eu sei que o problema é a condição de parada, como é C++, ñ tem scanf e tô pegando a string do usuário com getline, que também ñ é comparável a eof **/ while(1){ getline(cin, str2); if(!cin){ if(cin.eof()){ break; } } int i, j; for(i=0;i<str2.length();i++){ for(j=0;j<str1.length();j++){ if(str2.at(i) == str1.at(j)){ str2.at(i) = str1.at(j-1); } } } cout << str2 << endl; } return 0; }
Tá dando runtime error mesmo com a checagem do eof, alguém sabe por quê? Também testei fazer o loop simplesmente while(cin), mas n funfo.
-
Unknown replied 4 years ago
Oie!
Fiz ese programa, que deu Wrong 100%, mas roda normalmente. Alguem podia dar uma ajuda?
abc = "QWERTYUIOP[]\ASDFGHJKL;'ZXCVBNM,./" linha = [] entrada = raw_input() entrada = entrada.upper() linha = entrada.split(" ") ret = 0 teste = [] cont = 0 cont2 = 1 for x in linha: while cont < len(x): ret = abc.find(x[cont]) ret -= 1 teste.append(abc[ret]) cont += 1 if cont == len(x) and cont2 < len(linha): teste.append(" ") cont2 += 1 cont = 0 total = "" for x in teste: total += x print total
-
Railton Thales replied 5 years ago
A desgraça desse problema pode conter mais de uma linha de entrada!!!!
-
Daniel Alves replied 5 years ago
Estou recebendo Presentation error, não sei onde esta o erro.
#include<stdio.h> #include<string.h> #define max 10000 int main(){ char c[]={"`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./"}; int t1 = strlen(c); char x[max]; int i, j; while(scanf(" %[^\n]s", x) != EOF){ int t2 = strlen(x); for(i=0; i<t2; i++){ if(x[i] != ' '){ for(j=0; j<t1; j++){ if(x[i] == c[j]){ x[i] = c[j-1]; break; } } } } printf("%s\n", x); } return 0; }
-
Rafael Klynger replied 5 years ago
Não to entendendo o que tá errado no meu código, eu fiz em python por isso tive que fazer algumas alterações na entrada, mas msm assim não tá passando, alguém poderia me ajudar?
tec = {'1':"`", '2':'1', '3':'2', '4':'3', '5':'4','6':'5', '7':'6', '8':'7', '9':'8', '0':'9', '-':'9','=':'-', 'W':'Q','E':'W','R':'E','T':'R','Y':'T','U':'Y', 'I':'U', 'O':'I','P':'O','S':'A','D':'S','F':'D','G':'F','H':'G','J':'H', 'K':'J','L':'K','X':'Z','C':'X','V':'C','B':'V','N':'B','M':'N', ',':'M','.':',','/':'.', ' ':' ', '[':'P',']':'[','\\':']', ';':'L',"'":';', 'A':'', 'Q':'', 'Z':'', '1':'', '`':''} texto = '' while True: try: entrada = raw_input() except EOFError: break texto += '\n' + entrada saida = '' for char in texto: if char != '\n': saida += tec[char] print saida
-
Rawda Yasser replied 5 years ago
Olá, alguém pode me ajudar a entender o problema? de erro 100%
entrada WERTYUIOP[SDFGHJKL]XCVBNM,. ;1234567890-=/\' saída QWERTYUIOPASDFGHJK[ZXCVBNM, L`1234567890-.];
include includeusing namespace std;
int main() { string s1 = "`1234567890-=QWERTYUIOP[]\ASDFGHJKL;'ZXCVBNM,./"; string s; string s2 = ""; getline(cin, s); for(int i = 0; i < s.size(); i++) { if(s[i] == ' ') s2 += ' '; else {
int x = s1.find(s[i]); s2 += s1[x-1]; } } cout << s2 << endl; return 0;
}
-
Gabriel Duarte replied 5 years ago
MODSeu código só funciona com uma entrada, porém o problema diz que são várias entradas e termina com EOF. Você pode fazer algo do tipo:
while(gets(linha)) { // Seu codigo todo aqui }
-
Ricardo Negreiros replied 5 years ago
Bugado?? Pq aparece o L depois do Z, na primeira parte do código??
https://goo.gl/photos/hr5mAdqYuFCQRq9z5
Segue o código. Se alguém me der um help, fico grato!
#include <stdio.h> #include <stdlib.h> #include <string.h> main(){ char phrase[5000]; int i; while(scanf("%[^\n]s", phrase)!=EOF){ getchar(); for(i=0; i<strlen(phrase); i++){ if(phrase[i]=='='){phrase[i]='-';} else if(phrase[i]=='-'){phrase[i]='0';} else if(phrase[i]=='0'){phrase[i]='9';} else if(phrase[i]=='9'){phrase[i]='8';} else if(phrase[i]=='8'){phrase[i]='7';} else if(phrase[i]=='7'){phrase[i]='6';} else if(phrase[i]=='6'){phrase[i]='5';} else if(phrase[i]=='5'){phrase[i]='4';} else if(phrase[i]=='4'){phrase[i]='3';} else if(phrase[i]=='3'){phrase[i]='2';} else if(phrase[i]=='2'){phrase[i]='1';} else if(phrase[i]=='1'){phrase[i]='`';} else if(phrase[i]=='\\'){phrase[i]=']';} else if(phrase[i]==']'){phrase[i]='[';} else if(phrase[i]=='['){phrase[i]='P';} else if(phrase[i]=='P'){phrase[i]='O';} else if(phrase[i]=='O'){phrase[i]='I';} else if(phrase[i]=='I'){phrase[i]='U';} else if(phrase[i]=='U'){phrase[i]='Y';} else if(phrase[i]=='Y'){phrase[i]='T';} else if(phrase[i]=='T'){phrase[i]='R';} else if(phrase[i]=='R'){phrase[i]='E';} else if(phrase[i]=='E'){phrase[i]='W';} else if(phrase[i]=='W'){phrase[i]='Q';} else if(phrase[i]=='\''){phrase[i]=';';} else if(phrase[i]==';'){phrase[i]='L';} else if(phrase[i]=='L'){phrase[i]='K';} else if(phrase[i]=='K'){phrase[i]='J';} else if(phrase[i]=='J'){phrase[i]='H';} else if(phrase[i]=='H'){phrase[i]='G';} else if(phrase[i]=='G'){phrase[i]='F';} else if(phrase[i]=='F'){phrase[i]='D';} else if(phrase[i]=='D'){phrase[i]='S';} else if(phrase[i]=='S'){phrase[i]='A';} else if(phrase[i]=='/'){phrase[i]='.';} else if(phrase[i]=='.'){phrase[i]=',';} else if(phrase[i]==','){phrase[i]='M';} else if(phrase[i]=='M'){phrase[i]='N';} else if(phrase[i]=='N'){phrase[i]='B';} else if(phrase[i]=='B'){phrase[i]='V';} else if(phrase[i]=='V'){phrase[i]='C';} else if(phrase[i]=='C'){phrase[i]='X';} else if(phrase[i]=='X'){phrase[i]='Z';} else phrase[i]=phrase[i]; } for(i=0; i<strlen(phrase); i++){ printf("%c", phrase[i]); } printf("\n"); } return 0; }
-
Thiago Reschützegger replied 5 years ago
Sempre fala que está 100% errado, mas não acho o erro. Eu testei com o toolkit e dá certo. Se alguém puder dar uma ajuda, por favor
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char palavra[5000]; int c,x; scanf(" %[^\n]s", palavra); c= strlen(palavra); for(x=0;x<=c;x++){ //LETRAS if(palavra[x]=='W'){ palavra[x]='Q'; } if(palavra[x]=='S'){ palavra[x]='A'; } if(palavra[x]=='X'){ palavra[x]='Z'; } if(palavra[x]=='E'){ palavra[x]='W'; } if(palavra[x]=='D'){ palavra[x]='S'; } if(palavra[x]=='C'){ palavra[x]='X'; } if(palavra[x]=='R'){ palavra[x]='E'; } if(palavra[x]=='F'){ palavra[x]='D'; } if(palavra[x]=='V'){ palavra[x]='C'; } if(palavra[x]=='T'){ palavra[x]='R'; } if(palavra[x]=='G'){ palavra[x]='F'; } if(palavra[x]=='B'){ palavra[x]='V'; } if(palavra[x]=='Y'){ palavra[x]='T'; } if(palavra[x]=='H'){ palavra[x]='G'; } if(palavra[x]=='N'){ palavra[x]='B'; } if(palavra[x]=='U'){ palavra[x]='Y'; } if(palavra[x]=='J'){ palavra[x]='H'; } if(palavra[x]=='M'){ palavra[x]='N'; } if(palavra[x]=='I'){ palavra[x]='U'; } if(palavra[x]=='K'){ palavra[x]='J'; } if(palavra[x]=='O'){ palavra[x]='I'; } if(palavra[x]=='L'){ palavra[x]='K'; } if(palavra[x]=='P'){ palavra[x]='O'; } //NUMEROS if(palavra[x]=='1'){ palavra[x]='`'; } if(palavra[x]=='2'){ palavra[x]='1'; } if(palavra[x]=='3'){ palavra[x]='2'; } if(palavra[x]=='4'){ palavra[x]='3'; } if(palavra[x]=='5'){ palavra[x]='4'; } if(palavra[x]=='6'){ palavra[x]='5'; } if(palavra[x]=='7'){ palavra[x]='6'; } if(palavra[x]=='8'){ palavra[x]='7'; } if(palavra[x]=='9'){ palavra[x]='8'; } if(palavra[x]=='0'){ palavra[x]='9'; } //SÍMBLOS if(palavra[x]=='-'){ palavra[x]='0'; } if(palavra[x]=='='){ palavra[x]='-'; } if(palavra[x]=='['){ palavra[x]='P'; } if(palavra[x]==';'){ palavra[x]='L'; } if(palavra[x]==','){ palavra[x]='M'; } if(palavra[x]=='.'){ palavra[x]=','; } if(palavra[x]=='/'){ palavra[x]='.'; } } printf("%s\n",palavra); return 0; }
-
🎈Renan Tashiro🎈 replied 5 years ago
O while que o colega falou antes é na hora que vai ler a entrada, ou seja, no seu getline.
while( getline(cin,texto) ){ ... for(int i=0;i<=n;i++){ ... } }
-
Samuel Granato replied 5 years ago
Acho que não entendi direto, eu substitui o for por while, que roda até encontrar no vetor o char de parada
while(texto[i]!=0){ //saídas dos char; i++; } cout <<endl;
O codigo funciona do mesmo jeito que antes, e continua com o WA.
-
Tailo Mateus replied 5 years ago
Samuel Granato, esse problema você deve ler como End Of File
Exemplo:
while(scanf("%c",&texto) != EOF) { //Codigo }