Skip to content

Commit d433f6f

Browse files
author
Tyler Witt
committed
Initial commit
1 parent 77e9575 commit d433f6f

6 files changed

+265
-0
lines changed

Bubble.cpp

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//Tyler Witt
2+
//CodeEval
3+
//Bubble.cpp
4+
5+
#include <iostream>
6+
#include <fstream>
7+
#include <string>
8+
#include <cstdlib>
9+
#include <vector>
10+
11+
using namespace std;
12+
13+
int getLimit(string& line);
14+
15+
vector<int> setvector(string line);
16+
17+
void bubble(vector<int>& myVec, int limit);
18+
19+
int main(int argc, char *argv[]) {
20+
ifstream stream(argv[1]);
21+
string line;
22+
vector<int> myVec;
23+
int limit;
24+
while (getline(stream, line)) {
25+
limit = getLimit(line);
26+
myVec = setvector(line);
27+
if (myVec.size() > 1)
28+
bubble(myVec, limit);
29+
for (vector<int>::iterator it = myVec.begin(); it != myVec.end(); it++){
30+
cout << *it;
31+
if (it != myVec.end() - 1)
32+
cout << " ";
33+
}
34+
cout << endl;
35+
}
36+
return 0;
37+
}
38+
39+
int getLimit(string& line){
40+
int limit = 0;
41+
if (line.find('|') >= 0){
42+
limit = atoi(line.substr(line.find('|') + 2, line.length()).c_str());
43+
line = line.substr(0, line.find('|') - 1);
44+
}
45+
return limit;
46+
}
47+
48+
vector<int> setvector(string line){
49+
vector<int> myVec;
50+
while (!line.empty()){
51+
myVec.push_back(atoi(line.substr(0, line.find(' ')).c_str()));
52+
if (line.find(' ') < line.length())
53+
line = line.substr(line.find(' ') + 1);
54+
else
55+
line = "";
56+
}
57+
return myVec;
58+
}
59+
60+
void bubble(vector<int>& myVec, int limit){
61+
int temp;
62+
for (int i = 0; i < limit; i++){
63+
for (int j = 0; j < myVec.size() - i - 1; j++){
64+
if (myVec[j] > myVec[j+1]){
65+
temp = myVec[j];
66+
myVec[j] = myVec[j+1];
67+
myVec[j+1] = temp;
68+
}
69+
}
70+
}
71+
}

CapitalPercent.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//Tyler Witt
2+
//CodeEval
3+
//CapitalPercent.cpp
4+
5+
#include <iostream>
6+
#include <iomanip>
7+
#include <fstream>
8+
9+
using namespace std;
10+
11+
void analyze(string line);
12+
13+
int main(int argc, char *argv[]) {
14+
ifstream stream(argv[1]);
15+
string line;
16+
while (getline(stream, line)) {
17+
analyze(line);
18+
}
19+
return 0;
20+
}
21+
22+
void analyze(string line){
23+
int upper = 0;
24+
int lower = 0;
25+
for (int i = 0; i < line.length(); i++){
26+
if(isupper(line[i]))
27+
upper++;
28+
if(islower(line[i]))
29+
lower++;
30+
}
31+
cout << "lowercase: " << fixed << setprecision(2) << (double)lower/(upper+lower) * 100 << " "
32+
<< "uppercase: " << fixed << setprecision(2) << (double)upper/(upper+lower) * 100 << endl;
33+
}

DataRecovery.cpp

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//Tyler Witt
2+
//CodeEval
3+
//DataRecovery.cpp
4+
5+
#include <iostream>
6+
#include <fstream>
7+
#include <string>
8+
#include <cstdlib>
9+
#include <map>
10+
11+
using namespace std;
12+
13+
string translate(string line);
14+
15+
int main(int argc, char *argv[]) {
16+
ifstream stream("input.txt");
17+
string line;
18+
while (getline(stream, line)) {
19+
cout << translate(line) << endl;
20+
}
21+
cin.get();
22+
return 0;
23+
}
24+
25+
string translate(string line){
26+
int ploc = 0;
27+
int wloc = 0;
28+
string positions = line.substr(line.find(';') + 1);
29+
string result = "";
30+
map<int, string> dict;
31+
int missing = 0;
32+
33+
line = line.substr(0, line.find(';'));
34+
35+
while (!positions.empty()){
36+
ploc = positions.find(' ');
37+
wloc = line.find(' ');
38+
if (ploc > positions.length())
39+
ploc = positions.length();
40+
if (wloc > line.length())
41+
wloc = line.length();
42+
dict[atoi(positions.substr(0, ploc).c_str())] = line.substr(0, wloc);
43+
if (ploc < positions.length())
44+
positions = positions.substr(ploc + 1);
45+
else
46+
positions = "";
47+
line = line.substr(wloc + 1);
48+
}
49+
50+
for (int i = 1; i <= dict.size(); i++){
51+
if (dict.find(i) == dict.end())
52+
missing = i;
53+
else if (missing == 0)
54+
missing = dict.size() + 1;
55+
}
56+
57+
dict[missing] = line;
58+
59+
for (int i = 1; i <= dict.size(); i++)
60+
result = result + dict[i] + " ";
61+
62+
dict.erase(dict.begin(), dict.end());
63+
64+
return result;
65+
}

FileSize.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//Tyler Witt
2+
//CodeEval
3+
//FileSize.cpp
4+
5+
#include <iostream>
6+
#include <fstream>
7+
8+
using namespace std;
9+
10+
int main(int argc, char *argv[]) {
11+
ifstream infile;
12+
infile.open(argv[1]);
13+
infile.seekg(0, ios::end);
14+
cout << infile.tellg() << endl;
15+
return 0;
16+
}

FizzBuzz.cpp

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//Tyler Witt
2+
//CodeEval
3+
//FizzBuzz.cpp
4+
5+
#include <iostream>
6+
#include <fstream>
7+
#include <cstdlib>
8+
#include <string>
9+
10+
using namespace std;
11+
12+
void fizzbuzz(string line);
13+
14+
int main(int argc, char *argv[]) {
15+
ifstream stream(argv[1]);
16+
string line;
17+
while (getline(stream, line)) {
18+
fizzbuzz(line);
19+
cout << endl;
20+
}
21+
return 0;
22+
}
23+
24+
void fizzbuzz(string line){
25+
int limit;
26+
int values[2];
27+
bool flag;
28+
for (int i = 0; i < 2; i++){
29+
values[i] = atoi(line.substr(0, line.find(' ')).c_str());
30+
line = line.substr(line.find(' ') + 1);
31+
}
32+
limit = atoi(line.c_str());
33+
34+
for (int i = 1; i <= limit; i++){
35+
flag = false;
36+
if (i % values[0] == 0){
37+
cout << "F";
38+
flag = true;
39+
}
40+
if (i % values[1] == 0){
41+
cout << "B";
42+
flag = true;
43+
}
44+
if (flag == false)
45+
cout << i;
46+
if (i < limit)
47+
cout << ' ';
48+
}
49+
}

SumDigits.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//Tyler Witt
2+
//CodeEval
3+
//SumDigits.cpp
4+
5+
#include <iostream>
6+
#include <fstream>
7+
8+
using namespace std;
9+
10+
int addDigits(int num);
11+
12+
int main(int argc, char *argv[]) {
13+
ifstream infile;
14+
int temp;
15+
infile.open(argv[1]);
16+
while (infile >> temp) {
17+
cout << addDigits(temp) << endl;
18+
}
19+
infile.close();
20+
return 0;
21+
}
22+
23+
int addDigits(int num){
24+
int sum = 0;
25+
while (num > 10){
26+
sum += num % 10;
27+
num /= 10;
28+
}
29+
sum += num;
30+
return sum;
31+
}

0 commit comments

Comments
 (0)