Exercise 1-1
Write a program that take inputs from command line and create a todo list.
Exercise 1-2
Take names from command line and create a list. Print out the sorted list.
Exercise 1-3
Take a list of students name and their score. Print the top 5 scores and their names.
Exercise 1-4
Take a list of pairs of numbers, which indicate pairs of nodes that is connected.
Provide two functions:
1. Output the connected clusters.
2. Return true or false if two nodes are connected.
1. Output the connected clusters.
2. Return true or false if two nodes are connected.
Exercise 1-5 What does this print out?
#include <cstdlib> // Prototypes of srand() and rand()
#include <ctime> // Prototype of time()
#include <iostream>
using namespace std;
int main()
{
int number, attempt;
char wb = 'r'; // Repeat or finish.
long sec;
time( &sec); // Get the time in seconds.
srand((unsigned)sec); // Seeds the random
// number generator
cout << "\n\n "
<< " ******* A NUMERICAL GAME *******" << endl;
cout << "\n\nRules of the game:" << endl;
while( wb == 'r')
{
cout << "I have a number between 1 and 15 in mind \n"
<< "You have three chances to guess correctly!\n"
<< endl;
number = (rand() % 15) + 1;
bool found = false; int count = 0;
while( !found && count < 3 )
{
cin.sync(); // Clear input buffer
cin.clear();
cout << ++count << ". attempt: ";
cin >> attempt;
if(attempt < number) cout << "too small!"<< endl;
else if(attempt > number) cout <<"too big!"<< endl;
else found = true;
}
if( !found) {
cout << "\nI won!"
<< " The number in question was: "
<< number << endl;
} else {
cout << "\nCongratulations! You won!" << endl;
}
cout << "Repeat —> <r> Finish —> <f>\n";
do {
cin.get(wb);
}
while( wb != 'r' && wb != 'f');
}
return 0;
}
Exercise 1-6
- Write a program that take inputs from command line and create a todo list.
- Take names from command line and create a list. Print out the sorted list.
- Take a list of numbers from input and search if a certain number is there.
Try different ways and analyze run time. - Take two n digit numbers and use an algorithm better than brute-force to multiply.
- Implement Karatsuba algorithm for integer multiplication
- Build a binary tree
- Take a list of pairs of indices and build a network from them. Then given any input number, search if it is in the network
- From above network, given any two numbers, return True if they are connected, otherwise return False.
- From above network, return the shortest path
Exercise 1-7
- Build a graph
- Search a graph to see if two nodes are connected
- Take "car" and return how many possible way to convert it to "let", one letter at a time.
- Take a list of students name and their score. Print the top 5 scores and their names.
No comments:
Post a Comment