Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
krysseltillada / i_m.cpp
Last active August 29, 2015 14:21
introduction to myself using std::cout
#include <iostream>
#include "std_lib_facilities.h"
int main()
{
/// name , age , school, why you choose com sci, hobbies
std::cout << " introduction to my self " << "\n"
<< " ----------------------- " << "\n"
<< " hi my name is kryssel t de leon " << "\n"
@krysseltillada
krysseltillada / cmp_a_v.cpp
Created May 22, 2015 15:18
comaparing arrays using pointers and vectors using iterators
#include <iostream>
#include <vector>
int main()
{
constexpr size_t n = 5;
int arr[n] = {1, 2, 3, 4, 5};
int arr_2[n] = {1, 2, 8, 4, 5};
for(unsigned i = 0; i < n; ++i) {
@krysseltillada
krysseltillada / p_arr.cpp
Last active August 29, 2015 14:21
printing values from 2d array using range for, subscripts and pointers
#include <iostream>
int main()
{
int ia[3][4] = {
{0, 1 ,2 ,3},
{4, 5, 6, 7},
{8, 9, 10, 11}
};
@krysseltillada
krysseltillada / odd.cpp
Created May 27, 2015 01:20
double up odd number using conditional operators
#include <iostream>
#include <vector>
int main()
{
std::vector<int> vec = {2 , 24, 1 , 3 ,5 ,6, 9, 11};
for (auto &v : vec) {
((v % 2) == 1) ? v += v : v = v;
}
@krysseltillada
krysseltillada / t_b.cpp
Created May 29, 2015 02:48
text to binary converter
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <bitset>
int main()
{
std::string filename, savefile;
std::string test;
@krysseltillada
krysseltillada / c_s.cpp
Created June 4, 2015 22:36
using conditional statements
#include <iostream> /// std::cout
#include <vector> /// std::vector; std::endl;
int main()
{
const std::vector<std::string> lgrade = {"F", "D", "C", "B", "A", "A++"};
const std::vector<std::string>::const_iterator igrade = lgrade.begin(); /// or std::begin()
auto grades = 80;
std::string lettergrade;
@krysseltillada
krysseltillada / co.cpp
Created June 4, 2015 22:44
using conditional operator
#include <iostream> /// std::cout
#include <vector> /// std::vector; std::endl;
int main()
{
const std::vector<std::string> lgrade = {"F", "D", "C", "B", "A", "A++"};
const std::vector<std::string>::const_iterator igrade = lgrade.begin(); /// or std::begin()
auto grades = 80;
std::string lettergrade;
@krysseltillada
krysseltillada / c.cpp
Created June 7, 2015 04:15
vowel, consonant, spaces, tabs, newline counter (using if && else if && else statement)
#include <iostream>
#include <string>
int main()
{
unsigned vowels = 0, consonants = 0, newline = 0, space = 0, tab = 0;
std::string str;
while (getline(std::cin,str)) {
@krysseltillada
krysseltillada / dw.cpp
Created June 7, 2015 08:29
counting duplicated words in a single line
#include <iostream>
#include <vector>
int main()
{
std::vector<std::string> vec;
std::string s , word, prev;
unsigned maxrepeats = 1, repeats = 1;
while (std::cin >> s)
@krysseltillada
krysseltillada / prefix.cpp
Created June 8, 2015 00:19
Determining whether one vector is a prefix of the other
#include <iostream>
#include <vector>
int main()
{
std::vector<int> vec1{0, 1, 1, 2}, vec2{0, 1, 1, 2, 3, 5, 8};
if(vec1.size() > vec2.size()) {
for (auto it1 = vec2.begin(), it2 = vec1.begin(); it1 != vec2.end() && it2 != vec2.end(); ++it1, ++it2) {
if (*it2 != *it1) {