iloveseahawks
BAN USERJust like asking you to implement itoa. first, find each digit d, then putch(d+'1'-1)
- iloveseahawks April 07, 2013I'd use a Hashtable with BandName as the key, and a sorted linkedlist of struct as the value. Every times a song is played, the linkedlist gets updated by removing the old Song and inserting a new song with song.times incremented.
Hashtable Band(string name, LinkedList<Songs> linkedList);
struct Songs
{
int times;
string title;
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SumAfterIterations
{
class Program
{
//A = {5, 3, 8, 9, 16}
//After one iteration A = {3-5,8-3,9-8,16-9}={-2,5,1,7}
//After second iteration A = {5-(-2),1-5,7-1} sum =7+(-4)+6=9
//Given an array, return sum after n iterations
static void Main(string[] args)
{
int[] A = new int[] { 5, 3, 8, 9, 16 };
int iterations = 12;
int ans = SumAfterNIterations(A, iterations);
Console.WriteLine("answer is {0}", ans);
}
static int SumAfterNIterations(int[] array, int iterations)
{
int sum = 0;
if (array == null) return 0;
if (array.Length == 1) return array[0];
if (iterations < 1)
{
foreach (int i in array)
sum += i;
return sum;
}
int len = array.Length;
int round = 0;
while (len > 1 && round++ < iterations)
{
sum = 0;
for (int i = 0; i < len - 1; i++)
{
array[i] = array[i + 1] - array[i];
sum += array[i];
}
len--;
}
return sum;
}
}
}
can't we use a stack? push every char to the stack, and pop them out upon enter.
- iloveseahawks March 26, 2013static bool IsItBST(Node root)
{
if (root == null) return true;
if (root.left == null)
{
if (root.right == null) return true;
else if (root.right.data < root.data) return false;
}
else
{
if (root.left.data > root.data) return false;
if (root.right == null) return true;
if (root.right.data < root.data) return false;
}
if (!IsItBST(root.left)) return false;
if (!IsItBST(root.right)) return false;
return true;
}
We can have a data structure defined like this:
- iloveseahawks July 24, 2013struct City
{ string Name,
string StateProvince,
string Country,
string Zip,
XCoordinate x,
YCoordinate y,
int Temerature
}
If City is found, return its Tempature;
else
{
find neighboring city within same zip,
if no zip find same stateprovince
calculate the distance of these cities via XCoordinate,YCoordinate
return the temperature of city obtained from previous step
}