This file contains hidden or 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
char *token = strtok(char *str, char *delim); // first time. | |
while(token != NULL){ | |
token = strtok(NULL, delim); // to retrieve the subsequent tokens. | |
} |
This file contains hidden or 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
/* thread 1 */ | |
char *str1 = "1,2,3", *token; | |
token = strtok(str1, ","); | |
while(token != NULL){ | |
token = strtok(NULL, delim); | |
} | |
/* thread 2 */ |
This file contains hidden or 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
string RainyRoad::isReachable(vector <string> road) { | |
int n = road[0].length(); | |
if(road[0][0] == 'W' || road[0][n-1] == 'W') | |
return "NO"; | |
for(int i = 0 ;i < n; i++){ | |
if(road[0][i] == 'W' && road[1][i] == 'W') | |
return "NO"; | |
} | |
return "YES"; | |
} |
This file contains hidden or 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
<?php | |
/* source: www.w3schools.com */ | |
$con = mysql_connect("localhost","peter","abc123"); | |
if (!$con){ | |
die('Could not connect: ' . mysql_error()); | |
} | |
mysql_select_db("my_db", $con); |
This file contains hidden or 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
# models.py | |
class Person(models.Model): | |
firstname = models.CharField(max_length=30) | |
lastname = models.CharField(max_length=30) | |
# views.py | |
def list_view(request): | |
person_list = Person.objects.all() |
This file contains hidden or 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
<ul> | |
{% for p in players %} | |
<li> | |
<div> {{ p.name }} </div> | |
<div> Statistics </div> | |
<ul> | |
{% for g in p.games %} | |
<li> {{p}} scored {{g.runs}} runs </li> | |
{% endfor %} | |
</ul> |
This file contains hidden or 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
<ul> | |
<li> | |
<div> A </div> | |
<div> Statistics </div> | |
<ul> | |
<li> A scored 10 runs </li> | |
<li> A scored 20 runs </li> | |
<li> A scored 30 runs </li> | |
</ul> | |
</li> |
This file contains hidden or 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
import MySQLdb | |
host = '' | |
user = '' | |
passwd = '' | |
db = '' | |
# setup the connection | |
conn = MySQLdb.connect (host = host, user = user, passwd = passwd, db=db) | |
cursor = conn.cursor() |
This file contains hidden or 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 <iostream> | |
#include <vector> | |
#define SIZE 50 | |
#define debug(x) {cout << #x << " : " << x << endl ;} | |
using namespace std; | |
int main(){ | |
int a[SIZE] = {396, 549, 22, 819, 611, 972, 730, 638, 978, 342, 566, 514, 752, | |
871, 911, 172, 488, 542, 482, 974, 210, 474, 66, 387, 1, 872, 799, |
This file contains hidden or 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 <iostream> | |
#include <algorithm> | |
using namespace std; | |
int a[] = {4, 3, 1 ,2, 8, 3, 4}; | |
// int a[] = {1, 6, 2 ,3, 4, 5, 7}; | |
// int a[] = {0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15}; | |
// int a[] = {5,4,6,3,7}; | |
int N = sizeof(a)/sizeof(a[0]); |