Skip to content

Instantly share code, notes, and snippets.

string decode(string cipherText, int shift)
{
size_t len = cipherText.size();
string res(cipherText);
for(size_t i = 0; i < len; i++){
int c = res[i] - 'A';
if(c - shift < 0)
c = 26 + (c - shift);
else
c = c - shift;
@shnya
shnya / C++ split(find_first_of version)
Created December 9, 2010 16:56
C++ split : find_first_of version
vector<string> split(const string &str, char delim){
vector<string> res;
size_t current = 0, found;
while((found = str.find_first_of(delim, current)) != string::npos){
res.push_back(string(str, current, found - current));
current = found + 1;
}
res.push_back(string(str, current, str.size() - current));
return res;
}
@shnya
shnya / C++ split: find version
Created December 9, 2010 18:01
C++ split: find version
vector<string> split(const string &str, const string &delim){
vector<string> res;
size_t current = 0, found, delimlen = delim.size();
while((found = str.find(delim, current)) != string::npos){
res.push_back(string(str, current, found - current));
current = found + delimlen;
}
res.push_back(string(str, current, str.size() - current));
return res;
}
@shnya
shnya / C++ split: stringstream version
Created December 9, 2010 18:04
C++ split: stringstream version
vector<string> split(const string &str, char delim){
istringstream iss(str); string tmp; vector<string> res;
while(getline(iss, tmp, delim)) res.push_back(tmp);
return res;
}
@shnya
shnya / C++ split: copy, istream_iteartor, back_inserter version
Created December 9, 2010 18:04
C++ split: copy, istream_iteartor, back_inserter version
vector<string> split(const string &str){
istringstream iss(str); vector<string> res;
copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter(res));
return res;
}
@shnya
shnya / C++ split: boost version
Created December 9, 2010 18:05
C++ split: boost version
boost_split, vector<string> v;
boost::algorithm::split(v, str, bind2nd(equal_to<char>(), ' ')
@shnya
shnya / Surrogate Pair Test
Created December 24, 2010 12:54
Surrogate Pair Test (For Linx)
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <wchar.h>
#include <string>
#include <iconv.h>
@shnya
shnya / Surrogate Pair Test (For Windows)
Created December 24, 2010 13:49
Surrogate Pair Test (For Windows VC9)
#include "stdafx.h"
#include "Windows.h"
#include "winnls.h"
#include <string>
#include <cstdio>
using namespace std;
@shnya
shnya / file locking test
Created January 2, 2011 17:54
multithread file locking test based on http://kzk9.net/blog/2007/05/flock2.html
#include <sys/file.h>
#include <pthread.h>
#include <assert.h>
#include <semaphore.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
static int locked = 0;
@shnya
shnya / SRM 344 Div2 Level 1
Created January 4, 2011 17:54
SRM 344 Div2 Level 1
class Chessboard
{
public:
string changeNotation(string cell)
{
ostringstream oss;
if(cell[0] >= 'a' && cell[0] <= 'h'){
int c = static_cast<int>(cell[0]) - 'a' + 1;
int n = static_cast<int>(cell[1]) - '1';