Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions C++/Math and Others/Roman to Integer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <bits/stdc++.h>

class Solution
{
public:
int romanToInt(char c)
{
switch (c)
{
case 'I':
return 1;
case 'V':
return 5;
case 'X':
return 10;
case 'L':
return 50;
case 'C':
return 100;
case 'D':
return 500;
case 'M':
return 1000;
default:
return 0;
}
}

int romanToInt(string s)
{
int num = 0;
for (int i = 0; i < s.size(); i++)
{
if (i < s.size() - 1 && romanToInt(s[i]) < romanToInt(s[i + 1]))
{
num -= romanToInt(s[i]);
}
else
{
num += romanToInt(s[i]);
}
}
return num;
}
};
32 changes: 32 additions & 0 deletions Java/Patterns/DiamondPattern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import java.util.Scanner;

public class DiamondPattern {
public static void main(String args[]) {
int row, i, j, space = 1;
System.out.print("Enter the number of rows you want to print: ");
Scanner sc = new Scanner(System.in);
row = sc.nextInt();
space = row - 1;
for (j = 1; j <= row; j++) {
for (i = 1; i <= space; i++) {
System.out.print(" ");
}
space--;
for (i = 1; i <= 2 * j - 1; i++) {
System.out.print("*");
}
System.out.println("");
}
space = 1;
for (j = 1; j <= row - 1; j++) {
for (i = 1; i <= space; i++) {
System.out.print(" ");
}
space++;
for (i = 1; i <= 2 * (row - j) - 1; i++) {
System.out.print("*");
}
System.out.println("");
}
}
}
27 changes: 27 additions & 0 deletions Java/Patterns/PyramidPattern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public class PyramidPattern
{
public static void main(String args[])
{
//i for rows and j for columns
//row denotes the number of rows you want to print
int i, j, row = 6;
//Outer loop work for rows
for (i=0; i<row; i++)
{
//inner loop work for space
for (j=row-i; j>1; j--)
{
//prints space between two stars
System.out.print(" ");
}
//inner loop for columns
for (j=0; j<=i; j++ )
{
//prints star
System.out.print("* ");
}
//throws the cursor in a new line after printing each line
System.out.println();
}
}
}
19 changes: 19 additions & 0 deletions Java/Patterns/TrianglePattern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class TrianglePattern {

public static void tringlePattern(int n) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
if ((i + j) % 2 == 0) {
System.out.print("1");
} else {
System.out.print("0");
}
}
System.out.println();
}
}

public static void main(String args[]) {
tringlePattern(5);
}
}