Niestety, nie byliśmy w stanie w pełni poprawnie wyświetlić tego pliku, ponieważ nie jest zakodowany w UTF-8.
Możesz pobrać ten plik i spróbować otworzyć go samodzielnie.
#include <iostream> using namespace std; int tab[125][2]; int lista[125]; int licz = 0; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int k; cin>>k; tab[1][0] = 2; tab[1][1] = 3; int a = 2, b = 3; while (k > 0) { //cout<<"k = "<<k<<endl; if (k % 2 == 1) { lista[licz] = a; licz++; tab[a][1] = b; tab[b][0] = b + 1; tab[b][1] = b + 2; /* cout<<a<<" "<<b<<"\n"; cout<<b<<" "<<b + 1<<"\n"; cout<<b<<" "<<b + 2<<"\n"; */ } //teraz na krzy� else { tab[a][0] = b + 1; tab[a][1] = b + 2; tab[b][0] = b + 1; tab[b][1] = b + 2; /* cout<<a<<" "<<b + 1<<"\n"; cout<<a<<" "<<b + 2<<"\n"; cout<<b<<" "<<b + 1<<"\n"; cout<<b<<" "<<b + 2<<"\n"; */ } a += 2; b += 2; k /= 2; } //cout<<"a = "<<a<<" b = "<<b<<endl; int n = lista[licz - 1]; /*cout<<"oto lista\n"; for (int i = 0; i < licz; i++) { //cout<<lista[i]<<" "; } //cout<<endl;*/ cout<<n<<"\n"; for (int i = 1; i < n; i++) { if (tab[i][0] == 0) { //jest na li�cie cout<<n<<" "; if (tab[i][1] <= n) cout<<tab[i][1]<<"\n"; else cout<<-1<<"\n"; } else { if (tab[i][0] <= n) cout<<tab[i][0]<<" "; else cout<<-1<<" "; if (tab[i][1] <= n) cout<<tab[i][1]<<"\n"; else cout<<-1<<"\n"; } } cout<<-1<<" "<<-1<<"\n"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | #include <iostream> using namespace std; int tab[125][2]; int lista[125]; int licz = 0; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int k; cin>>k; tab[1][0] = 2; tab[1][1] = 3; int a = 2, b = 3; while (k > 0) { //cout<<"k = "<<k<<endl; if (k % 2 == 1) { lista[licz] = a; licz++; tab[a][1] = b; tab[b][0] = b + 1; tab[b][1] = b + 2; /* cout<<a<<" "<<b<<"\n"; cout<<b<<" "<<b + 1<<"\n"; cout<<b<<" "<<b + 2<<"\n"; */ } //teraz na krzy� else { tab[a][0] = b + 1; tab[a][1] = b + 2; tab[b][0] = b + 1; tab[b][1] = b + 2; /* cout<<a<<" "<<b + 1<<"\n"; cout<<a<<" "<<b + 2<<"\n"; cout<<b<<" "<<b + 1<<"\n"; cout<<b<<" "<<b + 2<<"\n"; */ } a += 2; b += 2; k /= 2; } //cout<<"a = "<<a<<" b = "<<b<<endl; int n = lista[licz - 1]; /*cout<<"oto lista\n"; for (int i = 0; i < licz; i++) { //cout<<lista[i]<<" "; } //cout<<endl;*/ cout<<n<<"\n"; for (int i = 1; i < n; i++) { if (tab[i][0] == 0) { //jest na li�cie cout<<n<<" "; if (tab[i][1] <= n) cout<<tab[i][1]<<"\n"; else cout<<-1<<"\n"; } else { if (tab[i][0] <= n) cout<<tab[i][0]<<" "; else cout<<-1<<" "; if (tab[i][1] <= n) cout<<tab[i][1]<<"\n"; else cout<<-1<<"\n"; } } cout<<-1<<" "<<-1<<"\n"; } |