This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
int freq[26]; | |
int main() { | |
int n; | |
cin >> n; | |
string s; | |
cin >> s; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
int main() { | |
int a, b; | |
cin >> a >> b; | |
if (a > b) | |
swap(a, b); // 'a' vira o menor elemento |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
// Cria uma estrutura que guarda um nó da pilha. | |
struct node { | |
int val; // O valor que está guardado no nó. | |
node *filho; // Um ponteiro pro próximo elemento da pilha. | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
// Cria uma estrutura que guarda um nó da pilha. | |
struct node { | |
int val; // O valor que está guardado no nó. | |
node *filho; // Um ponteiro pro próximo elemento da pilha. | |
}; | |
node *T; // Declaramos a nossa pilha |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() { | |
// Cria um novo inteiro dinamicamente e guarda a memória dele no ponteiro. | |
int *p = new int; | |
*p = 42; | |
cout << *p << '\n'; // 42 | |
// Também é possivel inicializar o new com algum valor | |
int *p2 = new int(27); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int* cria_ponteiro() { | |
int x = 42; | |
return &x; | |
} | |
int main() { | |
int *p = cria_ponteiro(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() { | |
int vet[5]; | |
vet[0] = 5; | |
vet[1] = 2; | |
vet[2] = 14; | |
vet[3] = 11; | |
vet[4] = 8; | |
// vet[] = 5 2 14 11 8 | |
// Escrever vet sem [] é a mesma coisa que um ponteiro pra primeira posição do vetor. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() { | |
int vet[5]; | |
vet[0] = 2; | |
vet[1] = 5; | |
vet[2] = 8; | |
vet[3] = 11; | |
vet[4] = 14; | |
// vet[] = 2 5 8 11 14 | |
// Criamos um ponteiro que aponta pra primeira posição do vetor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() { | |
int x; | |
// O scanf recebe um ponteiro, logo é passado o endereço de memória da | |
// variável como argumento. | |
scanf("%d", &x); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A função agora recebe um ponteiro como parâmetro | |
void modifica(int *p) { | |
*p = (*p) + 3; | |
} | |
int main() { | |
int x = 5; | |
int *p = &x; | |
cout << x << '\n'; // 5 |
NewerOlder