Soapi.cpp
This commit is contained in:
@@ -7,6 +7,19 @@ using System.Threading.Tasks;
|
|||||||
namespace Countdown_Numbers_Game {
|
namespace Countdown_Numbers_Game {
|
||||||
class Program {
|
class Program {
|
||||||
static void Main(string[] args) {
|
static void Main(string[] args) {
|
||||||
|
|
||||||
|
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||||
|
Console.WriteLine(" 888 888 ");
|
||||||
|
Console.WriteLine(" 888 888 ");
|
||||||
|
Console.WriteLine(" 888 888 ");
|
||||||
|
Console.WriteLine(" .d8888b .d88b. 888 88888888b. 888888 .d88888 .d88b. 888 888 88888888b. ");
|
||||||
|
Console.WriteLine("d88P\" d88\"\"88b888 888888 \"88b888 d88\" 888d88\"\"88b888 888 888888 \"88b ");
|
||||||
|
Console.WriteLine("888 888 888888 888888 888888 888 888888 888888 888 888888 888 ");
|
||||||
|
Console.WriteLine("Y88b. Y88..88PY88b 888888 888Y88b. Y88b 888Y88..88PY88b 888 d88P888 888 ");
|
||||||
|
Console.WriteLine(" \"Y8888P \"Y88P\" \"Y88888888 888 \"Y888 \"Y88888 \"Y88P\" \"Y8888888P\" 888 888 ");
|
||||||
|
Console.WriteLine("");
|
||||||
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
|
||||||
Program p = new Program();
|
Program p = new Program();
|
||||||
p.getInput();
|
p.getInput();
|
||||||
}
|
}
|
||||||
@@ -46,33 +59,34 @@ namespace Countdown_Numbers_Game {
|
|||||||
string output = solve.getSolution(target, inputArray);
|
string output = solve.getSolution(target, inputArray);
|
||||||
|
|
||||||
if (output == "false") {
|
if (output == "false") {
|
||||||
|
Console.WriteLine("A soulution could not be found... \nPress any key to exit...");
|
||||||
} else {
|
} else {
|
||||||
|
Console.WriteLine("Solution found: " + output);
|
||||||
|
Console.WriteLine("Press any key to exit...");
|
||||||
}
|
}
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
class Solver {
|
class Solver {
|
||||||
|
|
||||||
public string getSolution(int target, int[] inputArray) {
|
public string getSolution(int target, int[] inputArray) {
|
||||||
inputArray = SortArray(inputArray);
|
inputArray = SortArray(inputArray);
|
||||||
|
|
||||||
|
Console.Write("Sorted Array: ");
|
||||||
for (int i = 0; i < inputArray.Length; i++) {
|
for (int i = 0; i < inputArray.Length; i++) {
|
||||||
Console.Write(inputArray[i] + " ");
|
Console.Write(inputArray[i] + " ");
|
||||||
}
|
}
|
||||||
|
Console.WriteLine();
|
||||||
|
|
||||||
if (!isPossible(target, inputArray)) {
|
if (!isPossible(target, inputArray)) {
|
||||||
return "false";
|
return "false";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return findMethod(target, inputArray);
|
return findMethod(target, inputArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool isPossible(int target, int[] inputArray) {
|
private bool isPossible(int target, int[] inputArray) {
|
||||||
for (int i = 1; i < inputArray.Length; i++) {
|
for (int i = 1; i < inputArray.Length; i++) {
|
||||||
if (inputArray[i] + inputArray[i-1] == target {
|
if (inputArray[i] + inputArray[i-1] == target) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,6 +95,11 @@ namespace Countdown_Numbers_Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private string findMethod(int target, int[] inputArray) {
|
private string findMethod(int target, int[] inputArray) {
|
||||||
|
for (int i = 1; i < inputArray.Length; i++) {
|
||||||
|
if (inputArray[i] + inputArray[i - 1] == target) {
|
||||||
|
return inputArray[i] + " + " + inputArray[i-1] + " = " + target;
|
||||||
|
}
|
||||||
|
}
|
||||||
return " ";
|
return " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
8
C++/Soph/classes.h
Normal file
8
C++/Soph/classes.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#include <string>
|
||||||
|
using namespace std;
|
||||||
|
class Person {
|
||||||
|
public:
|
||||||
|
string cute() {
|
||||||
|
return "true";
|
||||||
|
};
|
||||||
|
};
|
||||||
13
C++/Soph/soapi.cpp
Normal file
13
C++/Soph/soapi.cpp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#include "classes.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Person Soapi;
|
||||||
|
string s;
|
||||||
|
cout << "Soapi.cute() = " << Soapi.cute() << "\n";
|
||||||
|
cin >> s;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user