CS1020 SIT IN LAB 1 Pattern Matching. Problem Given a RxC letters matrix and a RpxCp pattern matrix,find how many ways to match the patterns and letters.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Functional Programming Lecture 10 - type checking.
CS110 Programming Language I
Designing Algorithms Csci 107 Lecture 4. Outline Last time Computing 1+2+…+n Adding 2 n-digit numbers Today: More algorithms Sequential search Variations.
Expanding Predefined Types Karl Schnaitter November 30, 2004.
Computer Generated Jazz
Princeton University COS 226 Algorithms and Data Structures Spring Knuth-Morris-Pratt Reference: Chapter 19, Algorithms.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
CMPUT 101 Lab #6 October 29, :00 – 17:00. Array in C/C++ Array is a structure type variable. One dimension of array int: int num[3]; There are.
Chapter 1 pp 1-14 Properties of Algorithms Pseudocode.
Designing Algorithms Csci 107 Lecture 4.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
CS1020E Sitin 1 Discussion -- Counting Palindromes.
Lexical Analysis - An Introduction. The Front End The purpose of the front end is to deal with the input language Perform a membership test: code  source.
CP104 Introduction to Programming Selection Structures_3 Lecture 11 __ 1 The Switch Statement The switch statement provides another means to select one.
CS1101: Programming Methodology Aaron Tan.
Required Functions for Program 3 int readUntilValidBaseRead( ); int readNumbersReturningValue( int base ); int decimalValueOf( char chDigit ); bool isValid(
Examples of comparing strings. “ABC” = “ABC”? yes “ABC” = “ ABC”? No! note the space up front “ABC” = “abc” ? No! Totally different letters “ABC” = “ABCD”?
Branches and Program Design
Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
1 CS161 Introduction to Computer Science Topic #8.
Char ch; ch ‘L’‘X’‘V’‘I’ As in Roman numerals Want to give each a value, n say switch (ch) { case ‘I’:n = 1; break; case ‘V’:n = 5; break; … default:cout.
A: A: double “4” A: “34” 4.
Contest Algorithms January 2016 Pseudo-code for backtracking search, and three examples (all subsets, permutations, and 8- queens). 4. Backtracking 1Contest.
LOOPING IN C. What would be the output of the following program main( ) { int j ; while ( j
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Midterm 2 Review Notes on the CS 5 midterm Take-home exam due by 5:00 pm Sunday evening (11/14) Hand in your solutions under the door of my office, Olin.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
Quiz 1 Exam 1 Next Monday. Nested if Statements if (myGrade >= 80) if (myGrade >= 90) System.out.println(“You have an A!” ); else System.out.println(“You.
Java for Beginners University Greenwich Computing At School DASCO
Java String Methods - Codehs
Decision making If.. else statement.
Pseudo-code 1 Running time of algorithm is O(n)
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
CprE 185: Intro to Problem Solving (using C)
CS1020 – Data Structures And Algorithms 1 AY Semester 2
Java for Beginners University Greenwich Computing At School DASCO
Decisions Chapter 4.
Sit-In Lab 1 Ob-CHESS-ion
Incrementing ITP © Ron Poet Lecture 8.
Some problems for your consideration
An Introduction to Java – Part I
Advanced Programming Behnam Hatami Fall 2017.
Review Operation Bingo
Java for Beginners University Greenwich Computing At School DASCO
null, true, and false are also reserved.
نوع داده هاي انتزاعي Abstract Data Types
Compound Assignment Operators in C++
محاضرة 1: مقدمة للمسـاق و مراجعـة للأساسيـات
Selection CSCE 121 J. Michael Moore.
SELECTION STATEMENTS (2)
DESICION TABLE Decision tables are precise and compact way to model complicated logic. Decision table is useful when input and output data can be.
الوحدة الرابعة البرمجة وصياغة حل المسائل البرمجة وأهميتها أهداف الدرس الأول مفهوم البرمجة. الفرق بين المبرمج ومستخدم البرنامج. الحاجة إلى البرامج.
Decision making If statement.
Logical Operations In Matlab.
Differences between Java and C
If Statements.
SELECTIONS STATEMENTS
Java for Beginners University Greenwich Computing At School DASCO
Programming Concepts and Database
Nate Brunelle Today: Conditional Decision Statements
Fundamental Programming
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
CSCE 206 Lab Structured Programming in C
Boolean in C++ CSCE 121.
Lec 21 More Fun with Arrays: For Loops
3.0 - Design A software design specifies how a program will accomplish its requirements A design includes one or more algorithms to accomplish its goal.
COMPUTING.
Presentation transcript:

CS1020 SIT IN LAB 1 Pattern Matching

Problem Given a RxC letters matrix and a RpxCp pattern matrix,find how many ways to match the patterns and letters. Rp <= R <= 50 && Cp <= C <= 50 An asterisk “*” is used (in the pattern matrix) if any letter can be used for that cell.

Example Sample Input: 6 2 AAAXAA CCDXCX 2 2 AA C* Sample Output: 3

Algorithm Brute Force: Match the letters 1 character by 1 character. Letters: A A A X A A C C D X C X Patterns: A A C *

Algorithm Brute Force: Match the letters 1 character by 1 character. Letters: A A A X A A C C D X C X Patterns: A A C *

Algorithm Brute Force: Match the letters 1 character by 1 character. Letters: A A A X A A C C D X C X Patterns: A A C *

Algorithm Brute Force: Match the letters 1 character by 1 character. Letters: A A A X A A C C D X C X Patterns: A A C *

Algorithm Brute Force: Match the letters 1 character by 1 character. Letters: A A A X A A C C D X C X Patterns: A A C *

Sample Code (Pseudocode) While ( Checking each cell in letters matrix) { While (Matching each cell in patterns matrix) { if (Not all match) { break; } else { add one way; } } }

Java code (ANY_CHARACTER = ‘*’) int calculateNumberOfWays(int letterRow, int letterColumn, char[][] letterMatrix, int patternRow, int patternColumn, char[][] patternMatrix) { int ways = 0; for (int i = 0; i <= letterRow - patternRow; i++) { for (int j = 0; j <= letterColumn - patternColumn; j++) { boolean isMatched = true; for (int k = 0; k < patternRow; k++) { for (int l = 0; l < patternColumn; l++) { if (patternMatrix[k][l] == '*' || patternMatrix[k][l] == letterMatrix[i+k][j+l]) { continue; } else { isMatched = false; break; } } } if (isMatched) { ways++; } } } return ways; }