Module 5: Load a grid (part 2)
This commit is contained in:
parent
581207aa43
commit
0f86a88375
37
a.c
37
a.c
@ -1,20 +1,31 @@
|
||||
#include <iostream> // library for printing
|
||||
#include <string> // support for strings
|
||||
using namespace std;
|
||||
#include <iostream> // library for printing
|
||||
#include <string> // support for strings
|
||||
#include <vector> // support for vectors
|
||||
#include <assert.h>
|
||||
using namespace std;
|
||||
|
||||
// For compiling C++ code
|
||||
// g++ a.c -o a
|
||||
|
||||
int main()
|
||||
{
|
||||
vector<string> grid;
|
||||
|
||||
int main() {
|
||||
string s0 = "DOG....";
|
||||
string s1 = "---....";
|
||||
string s2 = "----...";
|
||||
string s3 = "-------";
|
||||
string s4 = "...----";
|
||||
string s5 = "....---";
|
||||
string s6 = "....CAT";
|
||||
grid.push_back("DOG....");
|
||||
grid.push_back("---....");
|
||||
grid.push_back("----...");
|
||||
grid.push_back("-------");
|
||||
grid.push_back("...----");
|
||||
grid.push_back("....---");
|
||||
grid.push_back("....CAT");
|
||||
|
||||
s0.append("EXTRA!!");
|
||||
cout << "s0 is now: " << s0 << "\n";
|
||||
int rows = grid.size();
|
||||
int cols = grid[0].size();
|
||||
for (string s : grid)
|
||||
{
|
||||
assert(s.size() == cols);
|
||||
}
|
||||
|
||||
cout << "rows=" << rows << "\n";
|
||||
cout << "cols=" << cols << "\n";
|
||||
}
|
25
a.py
25
a.py
@ -1,11 +1,18 @@
|
||||
if __name__ == "__main__":
|
||||
s0 = "DOG...."
|
||||
s1 = "---...."
|
||||
s2 = "----..."
|
||||
s3 = "-------"
|
||||
s4 = "...----"
|
||||
s5 = "....---"
|
||||
s6 = "....CAT"
|
||||
grid = []
|
||||
|
||||
s0 += "EXTRA!!"
|
||||
print(s0)
|
||||
grid.append("DOG....")
|
||||
grid.append("---....")
|
||||
grid.append("----...")
|
||||
grid.append("-------")
|
||||
grid.append("...----")
|
||||
grid.append("....---")
|
||||
grid.append("....CAT")
|
||||
|
||||
rows = len(grid)
|
||||
cols = len(grid[0])
|
||||
for s in grid:
|
||||
assert(len(s) == cols)
|
||||
|
||||
print(f"rows={rows}")
|
||||
print(f"cols={cols}")
|
Loading…
x
Reference in New Issue
Block a user