#1810
CifreGen5
Un program citeşte o valoare naturală nenulă impară pentru n
şi apoi generează şi afişează în ordine crescătoare lexicografic toate combinaţiile formate din n
cifre care îndeplinesc următoarele proprietăţi:
- încep şi se termină cu 0
;
- modulul diferenţei între oricare două cifre alăturate dintr-o combinaţie este 1
.
Problema | CifreGen5 | Operații I/O | tastatură/ecran |
---|---|---|---|
Limita timp | 0.1 secunde | Limita memorie |
Total: 64 MB
/
Stivă 8 MB
|
Id soluție | #25960241 | Utilizator | |
Fișier | cifregen5.cpp | Dimensiune | 1.39 KB |
Data încărcării | 19 Noiembrie 2020, 23:46 | Scor / rezultat | Eroare de compilare |
cifregen5.cpp:1:20: warning: extra tokens at end of #include directive [enabled by default] #include <iostream>#include <cmath>#include <cstring>using namespace std;#define NR 20int x[NR],p,k,nr;char a[5000][20]; ^ cifregen5.cpp:1:45: warning: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wliteral-suffix] #include <iostream>#include <cmath>#include <cstring>using namespace std;#define NR 20int x[NR],p,k,nr;char a[5000][20]; ^ cifregen5.cpp: In function 'void init(int)': cifregen5.cpp:2:22: error: 'x' was not declared in this scope void init(int k){ x[k]=0;} ^ cifregen5.cpp: In function 'int succesor(int)': cifregen5.cpp:3:28: error: 'x' was not declared in this scope int succesor(int k){ if(x[k]<10) return 1; else return 0;} ^ cifregen5.cpp: In function 'int continuare(int)': cifregen5.cpp:4:40: error: 'x' was not declared in this scope int continuare(int k){ if(k==1&&abs(x[k]-2)!=1) return 0; if(k==p&&abs(x[k]-2)!=1) return 0; for(int i=2;i<=k;++i) if(abs(x[i]-x[i-1])!=1) return 0; return 1;} ^ cifregen5.cpp:4:78: error: 'p' was not declared in this scope int continuare(int k){ if(k==1&&abs(x[k]-2)!=1) return 0; if(k==p&&abs(x[k]-2)!=1) return 0; for(int i=2;i<=k;++i) if(abs(x[i]-x[i-1])!=1) return 0; return 1;} ^ cifregen5.cpp:4:85: error: 'x' was not declared in this scope int continuare(int k){ if(k==1&&abs(x[k]-2)!=1) return 0; if(k==p&&abs(x[k]-2)!=1) return 0; for(int i=2;i<=k;++i) if(abs(x[i]-x[i-1])!=1) return 0; return 1;} ^ cifregen5.cpp:4:153: error: 'x' was not declared in this scope int continuare(int k){ if(k==1&&abs(x[k]-2)!=1) return 0; if(k==p&&abs(x[k]-2)!=1) return 0; for(int i=2;i<=k;++i) if(abs(x[i]-x[i-1])!=1) return 0; return 1;} ^ cifregen5.cpp: In function 'int solutie(int)': cifregen5.cpp:5:30: error: 'p' was not declared in this scope int solutie(int k){ if(k==p+1) return 1; else return 0;} ^ cifregen5.cpp: In function 'void retin()': cifregen5.cpp:6:18: error: 'a' was not declared in this scope void retin(){ a[nr][0]='0',a[nr][1]='1'; for(int i=1;i<=p;i++) a[nr][i+1]='0'+x[i]-1; a[nr][p+2]='1',a[nr][p+3]='0'; a[nr][p+4]='\0'; ++nr;} ^ cifregen5.cpp:6:20: error: 'nr' was not declared in this scope void retin(){ a[nr][0]='0',a[nr][1]='1'; for(int i=1;i<=p;i++) a[nr][i+1]='0'+x[i]-1; a[nr][p+2]='1',a[nr][p+3]='0'; a[nr][p+4]='\0'; ++nr;} ^ cifregen5.cpp:6:63: error: 'p' was not declared in this scope void retin(){ a[nr][0]='0',a[nr][1]='1'; for(int i=1;i<=p;i++) a[nr][i+1]='0'+x[i]-1; a[nr][p+2]='1',a[nr][p+3]='0'; a[nr][p+4]='\0'; ++nr;} ^ cifregen5.cpp:6:92: error: 'x' was not declared in this scope void retin(){ a[nr][0]='0',a[nr][1]='1'; for(int i=1;i<=p;i++) a[nr][i+1]='0'+x[i]-1; a[nr][p+2]='1',a[nr][p+3]='0'; a[nr][p+4]='\0'; ++nr;} ^ cifregen5.cpp:6:109: error: 'p' was not declared in this scope void retin(){ a[nr][0]='0',a[nr][1]='1'; for(int i=1;i<=p;i++) a[nr][i+1]='0'+x[i]-1; a[nr][p+2]='1',a[nr][p+3]='0'; a[nr][p+4]='\0'; ++nr;} ^ cifregen5.cpp: In function 'void backtracking()': cifregen5.cpp:7:209: error: 'x' was not declared in this scope void backtracking(){ int k; k=1; init(k); while(k>0) if(solutie(k)) { retin(); k--; } else if(succesor(k)) { x[k]++; if(continuare(k)) k++; } else init(k),k--;} ^ cifregen5.cpp: In function 'int main()': cifregen5.cpp:8:16: error: 'cin' was not declared in this scope int main(){ cin>>p; if(p%2==0) return 0; if(p==3) cout<<"010\n"; else { p-=4,backtracking(); char aux[20]; for(int i=0;i<nr-1;i++) for(int j=i+1;j<=nr-1;++j) if(strcmp(a[i],a[j])==1) strcpy(aux,a[i]),strcpy(a[i],a[j]),strcpy(a[j],aux); for(int i=0;i<nr;++i) cout<<a[i]<<'\n'; } return 0;} ^ cifregen5.cpp:8:16: note: suggested alternative: In file included from cifregen5.cpp:1:0: /usr/include/c++/4.8/iostream:60:18: note: 'std::cin' extern istream cin; /// Linked to standard input ^ cifregen5.cpp:8:21: error: 'p' was not declared in this scope int main(){ cin>>p; if(p%2==0) return 0; if(p==3) cout<<"010\n"; else { p-=4,backtracking(); char aux[20]; for(int i=0;i<nr-1;i++) for(int j=i+1;j<=nr-1;++j) if(strcmp(a[i],a[j])==1) strcpy(aux,a[i]),strcpy(a[i],a[j]),strcpy(a[j],aux); for(int i=0;i<nr;++i) cout<<a[i]<<'\n'; } return 0;} ^ cifregen5.cpp:8:74: error: 'cout' was not declared in this scope int main(){ cin>>p; if(p%2==0) return 0; if(p==3) cout<<"010\n"; else { p-=4,backtracking(); char aux[20]; for(int i=0;i<nr-1;i++) for(int j=i+1;j<=nr-1;++j) if(strcmp(a[i],a[j])==1) strcpy(aux,a[i]),strcpy(a[i],a[j]),strcpy(a[j],aux); for(int i=0;i<nr;++i) cout<<a[i]<<'\n'; } return 0;} ^ cifregen5.cpp:8:74: note: suggested alternative: In file included from cifregen5.cpp:1:0: /usr/include/c++/4.8/iostream:61:18: note: 'std::cout' extern ostream cout; /// Linked to standard output ^ cifregen5.cpp:8:172: error: 'nr' was not declared in this scope int main(){ cin>>p; if(p%2==0) return 0; if(p==3) cout<<"010\n"; else { p-=4,backtracking(); char aux[20]; for(int i=0;i<nr-1;i++) for(int j=i+1;j<=nr-1;++j) if(strcmp(a[i],a[j])==1) strcpy(aux,a[i]),strcpy(a[i],a[j]),strcpy(a[j],aux); for(int i=0;i<nr;++i) cout<<a[i]<<'\n'; } return 0;} ^ cifregen5.cpp:8:245: error: 'a' was not declared in this scope int main(){ cin>>p; if(p%2==0) return 0; if(p==3) cout<<"010\n"; else { p-=4,backtracking(); char aux[20]; for(int i=0;i<nr-1;i++) for(int j=i+1;j<=nr-1;++j) if(strcmp(a[i],a[j])==1) strcpy(aux,a[i]),strcpy(a[i],a[j]),strcpy(a[j],aux); for(int i=0;i<nr;++i) cout<<a[i]<<'\n'; } return 0;} ^ cifregen5.cpp:8:254: error: 'strcmp' was not declared in this scope int main(){ cin>>p; if(p%2==0) return 0; if(p==3) cout<<"010\n"; else { p-=4,backtracking(); char aux[20]; for(int i=0;i<nr-1;i++) for(int j=i+1;j<=nr-1;++j) if(strcmp(a[i],a[j])==1) strcpy(aux,a[i]),strcpy(a[i],a[j]),strcpy(a[j],aux); for(int i=0;i<nr;++i) cout<<a[i]<<'\n'; } return 0;} ^ cifregen5.cpp:8:294: error: 'strcpy' was not declared in this scope int main(){ cin>>p; if(p%2==0) return 0; if(p==3) cout<<"010\n"; else { p-=4,backtracking(); char aux[20]; for(int i=0;i<nr-1;i++) for(int j=i+1;j<=nr-1;++j) if(strcmp(a[i],a[j])==1) strcpy(aux,a[i]),strcpy(a[i],a[j]),strcpy(a[j],aux); for(int i=0;i<nr;++i) cout<<a[i]<<'\n'; } return 0;} ^ cifregen5.cpp:8:353: error: 'nr' was not declared in this scope int main(){ cin>>p; if(p%2==0) return 0; if(p==3) cout<<"010\n"; else { p-=4,backtracking(); char aux[20]; for(int i=0;i<nr-1;i++) for(int j=i+1;j<=nr-1;++j) if(strcmp(a[i],a[j])==1) strcpy(aux,a[i]),strcpy(a[i],a[j]),strcpy(a[j],aux); for(int i=0;i<nr;++i) cout<<a[i]<<'\n'; } return 0;} ^ cifregen5.cpp:8:372: error: 'cout' was not declared in this scope int main(){ cin>>p; if(p%2==0) return 0; if(p==3) cout<<"010\n"; else { p-=4,backtracking(); char aux[20]; for(int i=0;i<nr-1;i++) for(int j=i+1;j<=nr-1;++j) if(strcmp(a[i],a[j])==1) strcpy(aux,a[i]),strcpy(a[i],a[j]),strcpy(a[j],aux); for(int i=0;i<nr;++i) cout<<a[i]<<'\n'; } return 0;} ^ cifregen5.cpp:8:372: note: suggested alternative: In file included from cifregen5.cpp:1:0: /usr/include/c++/4.8/iostream:61:18: note: 'std::cout' extern ostream cout; /// Linked to standard output ^ cifregen5.cpp:8:378: error: 'a' was not declared in this scope int main(){ cin>>p; if(p%2==0) return 0; if(p==3) cout<<"010\n"; else { p-=4,backtracking(); char aux[20]; for(int i=0;i<nr-1;i++) for(int j=i+1;j<=nr-1;++j) if(strcmp(a[i],a[j])==1) strcpy(aux,a[i]),strcpy(a[i],a[j]),strcpy(a[j],aux); for(int i=0;i<nr;++i) cout<<a[i]<<'\n'; } return 0;} ^ cifregen5.cpp: In function 'int succesor(int)': cifregen5.cpp:3:78: warning: control reaches end of non-void function [-Wreturn-type] int succesor(int k){ if(x[k]<10) return 1; else return 0;} ^ cifregen5.cpp: In function 'int solutie(int)': cifregen5.cpp:5:76: warning: control reaches end of non-void function [-Wreturn-type] int solutie(int k){ if(k==p+1) return 1; else return 0;} ^
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema CifreGen5 face parte din prima categorie. Soluția propusă de tine va fi evaluată astfel:
Suma punctajelor acordate pe testele utilizate pentru verificare este 100. Astfel, soluția ta poate obține cel mult 100 de puncte, caz în care se poate considera corectă.