Totalmente de acuerdo con lo que has dicho, aunque yo iría más lejos e incluso diría que para programar en C/C++ lo ideal es usar Linux. Yo por ejemplo uso Kate como editor y compilo en la terminal con el g++.
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú#include <iostream>
#include <vector>
using namespace std;
void imprime(vector<int>& v, int x) {
for (int i = 0; i < v.size(); ++i) {
if ((x >> i)&1) cout << "+";
else cout << "-";
cout << v[i];
}
cout << endl;
}
int main() {
//Cantidad de numeros, resultado
int n, m;
cin >> n >> m;
//Lectura de los numeros
vector<int> v(n);
for (int i = 0; i < n; ++i) cin >> v[i];
//Solucion
for (int i = 0; i < (1 << n); ++i) {
int res = 0;
for (int j = 0; j < n; ++j) {
if ((i >> j)&1) res += v[j];
else res -= v[j];
}
if (res == m) imprime(v, i);
}
}
for (int i = 1; i < n; ++i)
for (int i = 1; i < n; i++)
#include <iostream>
using namespace std;
int factorial1(int n) { // Version iterativa
int result = 1;
for (int i = 2; i <= n; ++i) result *= i;
return result;
}
int factorial2(int n) { // Version iterativa
int result = 1;
for (int i = 2; i <= n; i++) result *= i;
return result;
}
int main() {
int n;
while (cin >> n) cout << factorial1(n) << " " << factorial2(n) << endl;
}
0
1
2
3
4
5
6
7
8
1 1
1 1
2 2
6 6
24 24
120 120
720 720
5040 5040
40320 40320
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;
int M[3][3];
int fila[] = {0, 2, 2, 2, 1, 1, 1, 0, 0, 0};
int col[] = {0, 0, 1, 2, 0, 1, 2, 0, 1, 2};
int incf[] = {0, 1, 1, -1};
int incc[] = {1, 1, 0, 1};
int check() {
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
for (int d = 0; d < 4; ++d) {
string s;
int f = i, c = j;
for (int h = 0; h < 3; ++h) {
if (f < 0 or f >= 3 or c < 0 or c >= 3) break;
s += char(M[f][c] + '0');
f += incf[d];
c += incc[d];
}
if (s == "111") return 1;
else if (s == "222") return 2;
}
}
}
return -1;
}
void draw() {
for (int i = 0; i < 50; ++i) cout << endl;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
if (M[i][j] == 0) cout << " ";
else if (M[i][j] == 1) cout << " X";
else cout << " O";
if (j != 2) cout << " |";
}
cout << endl;
if (i != 2) cout << "------------" << endl;
}
}
int rec(int &x, int &y, int torn) {
int best = -2;
int z, t;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
if (M[i][j] != 0) continue;
M[i][j] = torn;
if (check() == torn) {
x = i;
y = j;
M[i][j] = 0;
return 1;
}
int aux = rec(z, t, (torn == 1)?2:1);
if (aux == -2 or aux == 0) {
if (best < 0) {
best = 0;
x = i;
y = j;
}
}
else if (aux == -1) {
if (best < 1) {
best = 1;
x = i;
y = j;
M[i][j] = 0;
return best;
}
}
else if (aux == 1) {
if (best < -1) {
best = -1;
x = i;
y = j;
}
}
M[i][j] = 0;
}
}
return best;
}
void tira_pc() {
int x, y;
int aux = rec(x, y, 1);
M[x][y] = 1;
}
void tira_jug() {
int pos = -1;
while (pos < 1) {
cin >> pos;
if (pos < 1 or pos > 9) pos = -1;
else if (M[fila[pos]][col[pos]] != 0) pos = -1;
}
M[fila[pos]][col[pos]] = 2;
}
int main() {
memset(M, 0, sizeof(M));
int win = -1, torn = 0;
int qtt = 0;
draw();
while ((win = check()) < 0 and qtt < 9) {
if (torn == 1) tira_pc();
else tira_jug();
torn = 1 - torn;
draw();
++qtt;
}
if (win == 1) cout << "Gana el ordenador" << endl;
else if (win == 2) cout << "Ganas tu" << endl;
else cout << "Empate" << endl;
}
#include <iostream>
#include <vector>
#include <set>
#include <string.h>
using namespace std;
int nimber[105][3][3];
int grundy(int n, int a, int b) {
if (n == 0) return 0;
if (n == 1) {
if (not (a + b == 3)) return 1;
return 0;
}
if (nimber[n][a][b] == -1) {
set<int> A;
for (int i = 1; i < n - 1; ++i) {
A.insert(grundy(i, a, 1)^grundy(n - i - 1, 1, b));
A.insert(grundy(i, a, 2)^grundy(n - i - 1, 2, b));
}
if (a != 1) A.insert(grundy(n - 1, 1, b));
if (a != 2) A.insert(grundy(n - 1, 2, b));
if (b != 1) A.insert(grundy(n - 1, a, 1));
if (b != 2) A.insert(grundy(n - 1, a, 2));
nimber[n][a][b] = 0;
while (A.count(nimber[n][a][b])) ++nimber[n][a][b];
}
return nimber[n][a][b];
}
int main() {
memset(nimber, -1, sizeof(nimber));
int q;
cin >> q;
while (q--) {
string s;
cin >> s;
int ant = 0, res = 0, qtt = 0, turno = 0;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == 'X') {
res ^= grundy(qtt, ant, 1);
ant = 1;
qtt = 0;
++turno;
}
else if (s[i] == 'O') {
res ^= grundy(qtt, ant, 2);
ant = 2;
qtt = 0;
++turno;
}
else ++qtt;
}
res ^= grundy(qtt, ant, 0);
if (turno&1) cout << ((res == 0)?"Possible.":"Impossible.") << endl;
else cout << ((res != 0)?"Possible.":"Impossible.") << endl;
}
}
#include <iostream>
#include <vector>
#include <set>
using namespace std;
int grundy(int n, vector<int>& nimber) {
if (n == 0 or n == 1) return 0; //No hay movimientos posibles
if (nimber[n] == -1) {
set<int> A; //Guardare aqui los nimbers a los que se puede llegar
//Itero sobre la cantidad de puntos que dejo en el primer subjuego
for (int i = 0; i <= n - 2; ++i) A.insert(grundy(i, nimber)^grundy(n - i - 2, nimber));
//Busco el primero que no este, empezando por 0
nimber[n] = 0;
while (A.count(nimber[n])) ++nimber[n];
}
return nimber[n];
}
int main() {
int k;
cin >> k;
vector<int> nimber(k + 1, -1);
for (int i = 0; i <= k; ++i) cout << "N[" << i << "] = " << grundy(i, nimber) << endl;
}
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
string c = "0123456789ABCDEF";
int main() {
int n;
while (cin >> n and n > 0) {
vector<int> base;
for (int i = 2; i <= 16; ++i) {
string s;
int x = n;
while (x > 0) {
s += c[x%i];
x /= i;
}
string r = s;
reverse(s.begin(), s.end());
if (s == r) base.push_back(i);
}
if (base.size() == 0) cout << "Number " << n << " is not palindrom" << endl;
else {
cout << "Number " << n << " is palindrom in basis";
for (int i = 0; i < base.size(); ++i) cout << " " << base[i];
cout << endl;
}
}
}