Skip to content

Commit 76deb4c

Browse files
author
Carlos Leonard
committed
update
1 parent dbd0bb0 commit 76deb4c

12 files changed

+106
-8
lines changed

73_ClosestEnemy2.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,41 @@ For this input your program should return 2 because the closest enemy (2) is 2 s
1212

1313
#include <iostream>
1414
#include <string>
15+
#include <vector>
1516
using namespace std;
1617

17-
string ClosestEnemyII(string strArr[], int size)
18+
/*
19+
locate starting point
20+
check if the matrix has any enemies
21+
*/
22+
23+
int ClosestEnemyII(string strArr[], int size)
1824
{
25+
int startX, startY;
26+
bool enemyFound = false;
27+
28+
for (int x = 0; x < size; x++)
29+
{
30+
for (int y = 0; y < strArr[x].size(); y++)
31+
{
32+
if (strArr[x][y] == '1')
33+
{
34+
startX = x;
35+
startY = y;
36+
}
37+
38+
if (strArr[x][y] == '2')
39+
{
40+
enemyFound = true;
41+
}
42+
}
43+
}
44+
45+
if (!enemyFound)
46+
{
47+
return 0;
48+
}
49+
1950

2051
}
2152

74_SerialNumber.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// For this challenge you will be determining if a string produces a valid serial number.
2+
/*
3+
have the function SerialNumber(str) take the str parameter being passed and determine if it is a valid serial number with the following constraints:
4+
5+
1. It needs to contain three sets each with three digits (1 through 9) separated by a period.
6+
2. The first set of digits must add up to an even number.
7+
3. The second set of digits must add up to an odd number.
8+
4. The last digit in each set must be larger than the two previous digits in the same set.
9+
10+
If all the above constraints are met within the string, the your program should return the string true, otherwise your program should return the string false. For example: if str is "224.315.218" then your program should return "true".
11+
*/
12+
13+
#include <iostream>
14+
#include <string>
15+
using namespace std;
16+
17+
/*
18+
check that the size is correct
19+
check that only 1-9 are included
20+
add the first 3 digits
21+
add the second set
22+
check the last digit of each set
23+
*/
24+
25+
string SerialNumber(string str)
26+
{
27+
int first, second;
28+
29+
if (str.size() < 11)
30+
{
31+
return "false";
32+
}
33+
34+
for (int x = 0; x < str.size(); x++)
35+
{
36+
if (str[x] == '0')
37+
{
38+
return "false";
39+
}
40+
}
41+
42+
first = int(str[0]) + int(str[1]) + int(str[2]);
43+
second = int(str[4]) + int(str[5]) + int(str[6]);
44+
45+
if (first % 2 != 0 || second % 2 == 0)
46+
{
47+
return "false";
48+
}
49+
50+
if (str[2] < str[1] || str[2] < str[0] || str[6] < str[5] || str[6] < str[4] || str[10] < str[8] || str[10] < str[9])
51+
{
52+
return "false";
53+
}
54+
else
55+
{
56+
return "true";
57+
}
58+
}
59+
60+
int main()
61+
{
62+
cout << SerialNumber("224.315.218") << endl; // true
63+
cout << SerialNumber("11.124.667") << endl; // false
64+
cout << SerialNumber("114.568.112") << endl; // true
65+
return 0;
66+
}

Debug/Fun Practice.log

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
Build started 3/21/2017 5:28:59 PM.
1+
Build started 4/13/2017 1:04:49 PM.
22
1>Project "C:\Users\gutty333\Documents\Visual Studio 2013\Projects\Fun Practice\Fun Practice\Fun Practice.vcxproj" on node 2 (Build target(s)).
33
1>ClCompile:
4-
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /sdl /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _LIB /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\\" /Fd"Debug\vc120.pdb" /Gd /TP /analyze- /errorReport:prompt 72_GCF.cpp
5-
72_GCF.cpp
4+
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /sdl /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _LIB /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\\" /Fd"Debug\vc120.pdb" /Gd /TP /analyze- /errorReport:prompt 74_SerialNumber.cpp
5+
74_SerialNumber.cpp
6+
1>c:\users\gutty333\documents\visual studio 2013\projects\fun practice\fun practice\74_serialnumber.cpp(35): warning C4018: '<' : signed/unsigned mismatch
67
Link:
7-
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"C:\Users\gutty333\Documents\Visual Studio 2013\Projects\Fun Practice\Debug\Fun Practice.exe" /INCREMENTAL /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\Users\gutty333\Documents\Visual Studio 2013\Projects\Fun Practice\Debug\Fun Practice.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\gutty333\Documents\Visual Studio 2013\Projects\Fun Practice\Debug\Fun Practice.lib" /MACHINE:X86 Debug\72_GCF.obj
8+
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"C:\Users\gutty333\Documents\Visual Studio 2013\Projects\Fun Practice\Debug\Fun Practice.exe" /INCREMENTAL /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\Users\gutty333\Documents\Visual Studio 2013\Projects\Fun Practice\Debug\Fun Practice.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\gutty333\Documents\Visual Studio 2013\Projects\Fun Practice\Debug\Fun Practice.lib" /MACHINE:X86 Debug\74_SerialNumber.obj
89
Fun Practice.vcxproj -> C:\Users\gutty333\Documents\Visual Studio 2013\Projects\Fun Practice\Debug\Fun Practice.exe
910
1>Done Building Project "C:\Users\gutty333\Documents\Visual Studio 2013\Projects\Fun Practice\Fun Practice\Fun Practice.vcxproj" (Build target(s)).
1011

1112
Build succeeded.
1213

13-
Time Elapsed 00:00:01.25
14+
Time Elapsed 00:00:03.87
12.4 KB
Binary file not shown.
822 Bytes
Binary file not shown.
842 Bytes
Binary file not shown.
36 Bytes
Binary file not shown.
36 Bytes
Binary file not shown.
18 Bytes
Binary file not shown.

Debug/vc120.idb

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)