personas:jero98772:aprender_competiva
¡Esta es una revisión vieja del documento!
cosas competitiva notas y de c++
- cout«“hola ”«?
- “/n” es mas rapido que endl
- es mejor hacer string.push_back(caracter) que string+caracter, push_back es O(1), esto se deberia poder utilisar en otros lenguajes, en python NO por que los string son inmutables
- se puede sortitar , usar sort en vectores,arreglos, estructuras de datos,pair, string y vectores de strings
vectores
vector<int> v = {4,2,5,3,5,8,3};
sort(v.begin(),v.end());
arreglos
int n = 7; // array size
int a[] = {4,2,5,3,5,8,3};
sort(a,a+n);
strings
string s = "monkey"; sort(s.begin(), s.end());
pares
vector<pair<int,int>> v;
v.push_back({1,5});
v.push_back({2,3});
v.push_back({1,2});
sort(v.begin(), v.end());
tuplas
vector<tuple<int,int,int>> v;
v.push_back({2,1,4});
v.push_back({1,5,3});
v.push_back({2,1,3});
sort(v.begin(), v.end());
palabras
bool comp(string a, string b) {
if (a.size() != b.size()) return a.size() < b.size();
return a < b;
}
sort(v.begin(), v.end(), comp);
personas/jero98772/aprender_competiva.1679863913.txt.gz · Última modificación: por jero98772
