Commit 44a8c4b9 authored by Sanjna's avatar Sanjna

outLab8

parents
File added
File added
import java.util.*;
class q1
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
String input = sc.nextLine();
String inputs[] = input.split(",");
int l = inputs.length;
int start = Integer.parseInt(inputs[l-2].trim());
int end = Integer.parseInt(inputs[l-1].trim());
System.out.println(input.substring(start,end+1));
}
}
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Collections;
public class q2 {
public static void frequencyEle(int arrayElement[], int number) {
HashMap<Integer, Integer> arrayHash = new HashMap<Integer, Integer>();
for (int i=0; i<number; i++) {
if (arrayHash.containsKey(arrayElement[i])) {
arrayHash.put(arrayElement[i], arrayHash.get(arrayElement[i]) + 1);
}
else {
arrayHash.put(arrayElement[i], 1);
}
}
int maxValue = Collections.max(arrayHash.values());
System.out.println(maxValue);
}
public static void main(String[] args) {
Scanner size = new Scanner(System.in);
int number = size.nextInt();
int [] arrayElement = new int[number];
for (int i = 0; i < number; i++){
arrayElement[i] = size.nextInt();
}
frequencyEle(arrayElement, number);
}
}
\ No newline at end of file
File added
import java.util.Scanner;
import java.util.regex.*;
import java.util.ArrayList;
import java.lang.*;
public class q3 {
public boolean fun1(String myStr) {
// write your code here
return myStr!=null && myStr.chars().allMatch(Character::isLetterOrDigit) && myStr.length()<=5;
}
public boolean fun2(String myStr) {
// write your code here
return Pattern.compile("a*b+c").matcher(myStr).matches();
}
public boolean fun3(String myStr) {
// write your code here
return Pattern.compile("(?x) (?: a (?= a* (\\1?+ b)) )+ \\1").matcher(myStr).matches();
}
public ArrayList<String> fun4(String myStr, String patt) {
// write your code here
ArrayList<String> strings = new ArrayList<String>();
int n,i,j,k,match_j=0;
String str="",match="";
n = myStr.length();
i = 0;
while(i<n)
{
match = "";
for(j=i+1;j<=n;j++)
{
str = myStr.substring(i,j);
//System.out.println(str);
//System.out.println(patt);
if(Pattern.compile(patt).matcher(str).matches())
{
match = str;
match_j = j;
//System.out.println(match);
}
//else break;
}
if(match!=null && !match.isEmpty())
{
strings.add(match);
i = match_j;
}
else
i = i+1;
}
return strings;
}
}
\ No newline at end of file
File added
import java.text.SimpleDateFormat;
import java.util.Date;
import java.lang.*;
class timeThread implements Runnable
{
Thread t;
public void run()
{
while (true)
{
Date d = new Date();
SimpleDateFormat sdate = new SimpleDateFormat("hh:mm:ss");
try
{ t.sleep(1000);
System.out.println(sdate.format(d));
}
catch (InterruptedException e)
{ break;}
}
}
}
class q4{
public static void main(String args[])
{
Thread t1 = new Thread(new timeThread());
t1.start();
}
}
import java.util.Scanner;
import java.util.ArrayList;
public class q5 {
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
int numOfList = inp.nextInt();
ArrayList<ArrayList<Integer>> ipList = new ArrayList<ArrayList<Integer>>();
for(int i=0;i<numOfList;i++) {
ArrayList<Integer> tempList = new ArrayList<Integer>();
tempList.add(0);
int numOfElem = inp.nextInt();
for(int j=0;j<numOfElem;j++) {
int elem = inp.nextInt();
tempList.add(elem);
}
ipList.add(tempList);
}
String opStr = "";
int numOfQuery = inp.nextInt();
for(int k=0;k<numOfQuery;k++) {
try{
int listno = inp.nextInt();
int elemno = inp.nextInt();
opStr += ipList.get(listno-1).get(elemno)+"\n";
}catch(IndexOutOfBoundsException e) {
opStr += "ERROR!\n";
}
}
System.out.println(opStr.trim());
}
}
public class Matrix {
private float[][] matx;
//constructor 1
public Matrix(int a, float v) {
this.matx = new float[a][a];
for(int i=0;i<a;i++)
for(int j=0;j<a;j++)
this.matx[i][j]=v;
}
public Matrix(int a, int b, float v) {
this.matx = new float[a][b];
for(int i=0;i<a;i++)
for(int j=0;j<b;j++)
this.matx[i][j]=v;
}
public Matrix(int a, int b) {
this.matx = new float[a][b];
for(int i=0;i<a;i++)
for(int j=0;j<b;j++)
this.matx[i][j]=(float) 0.0;
}
public Matrix(int a) {
this.matx = new float[a][a];
for(int i=0;i<a;i++)
for(int j=0;j<a;j++)
this.matx[i][j]=(float) 0.0;
}
//2 add()
Matrix add(Matrix objB) {
int rownumA = this.getrows();
int colnumA = this.getcols();
int rownumB = objB.getrows();
int colnumB = objB.getcols();
Matrix opObj;
if((rownumA==rownumB) && (colnumA==colnumB)) {
opObj = new Matrix(rownumA,colnumA);
for(int i=0;i<rownumA;i++) {
for(int j=0; j<colnumA; j++) {
opObj.matx[i][j] = this.matx[i][j]+objB.matx[i][j];
}
}
}else {
System.out.println("Matrices cannot be added");
opObj = new Matrix(1,1,0);
}
return opObj;
}
//3 matmul()
Matrix matmul(Matrix objB) {
int rownumA = this.getrows();
int colnumA = this.getcols();
int rownumB = objB.getrows();
int colnumB = objB.getcols();
Matrix opObj;
if(colnumA==rownumB) {
opObj = new Matrix(rownumA, colnumB);
for(int i=0;i<rownumA;i++) {
for(int j=0; j<colnumB; j++) {
opObj.matx[i][j] = 0;
for(int k=0; k<colnumA; k++)
opObj.matx[i][j] += this.matx[i][k]*objB.matx[k][j];
}
}
}else {
System.out.println("Matrices cannot be multiplied");
opObj = new Matrix(1,1,0);
}
return opObj;
}
//4 scalarmul()
void scalarmul(int scalval) {
int rownum = this.getrows();
int colnum = this.getcols();
for(int i=0;i<rownum;i++) {
for(int j=0; j<colnum; j++) {
this.matx[i][j] *= scalval;
}
}
}
//5 getrows()
int getrows() {
return this.matx.length;
}
//6 getcols()
int getcols() {
return this.matx[0].length;
}
//7 getelem()
float getelem(int r, int c) {
try {
return this.matx[r][c];
}catch(IndexOutOfBoundsException e) {
System.out.println("Index out of bound");
return (float)-100;
}
}
//8 setelem()
void setelem(int r, int c, float val){
try {
this.matx[r][c] = val;
}catch(IndexOutOfBoundsException e) {
System.out.println("Index out of bound");
}
}
//9 printmatrix()
void printmatrix() {
int rownum = this.getrows();
int colnum = this.getcols();
for(int i=0;i<rownum;i++) {
String rowval = "";
for(int j=0; j<colnum; j++) {
rowval += this.matx[i][j]+" ";
}
rowval=rowval.trim();
System.out.println(rowval);
}
}
}
import java.io.*;
import java.lang.*;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;
public class q7 {
public static void main(String[] args) {
if(args.length > 0) {
try{
File file = new File(args[0]);
Scanner myReader = new Scanner(file);
String totalData = "";
while (myReader.hasNextLine()) {
String data = myReader.nextLine();
data = data.replaceAll("\\p{Punct}","");
data = data.replaceAll("\\b\\band\\b", "");
data = data.replaceAll("\\bthe\\b", "");
data = data.replaceAll("\\bis\\b", "");
data = data.replaceAll("\\bin\\b", "");
data = data.replaceAll("\\bat\\b", "");
data = data.replaceAll("\\bof\\b", "");
data = data.replaceAll("\\bhis\\b", "");
data = data.replaceAll("\\bher\\b", "");
data = data.replaceAll("\\bhim\\b", "");
totalData = totalData +" "+ data;
}
StringTokenizer st1 = new StringTokenizer(totalData);
ArrayList<String> dataArray = new ArrayList<>();
while (st1.hasMoreTokens()){
dataArray.add(st1.nextToken());
}
HashSet<String> dataSet = new HashSet<String>(dataArray);
HashMap<String, Integer> dataMap = new HashMap<String, Integer>();
for (String str : dataSet) {
dataMap.put(str, Collections.frequency(dataArray, str));
}
dataMap.entrySet().stream().sorted(Map.Entry.<String, Integer>comparingByValue().thenComparing(Map.Entry::getKey, String.CASE_INSENSITIVE_ORDER)).forEach(x -> System.out.println(x.getKey()+","+x.getValue()));
myReader.close();
}
catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
}
}
\ No newline at end of file
Looking back on a childhood filled with events and memories, I find it rather difficult to pick one that leaves me with the fabled "warm and fuzzy feelings."
As the daughter of an Air Force major, I had the pleasure of traveling across America in many moving trips.
I have visited the monstrous trees of the Sequoia National Forest, stood on the edge of the Grand Canyon and have jumped on the beds at Caesar's Palace in Lake Tahoe."
"The day I picked my dog up from the pound was one of the happiest days of both of our lives.
I had gone to the pound just a week earlier with the idea that I would just "look" at a puppy.
Of course, you can no more just look at those squiggling little faces so filled with hope and joy than you can stop the sun from setting in the evening.
I knew within minutes of walking in the door that I would get a puppy… but it wasn't until I saw him that I knew I had found my puppy."
"Looking for houses was supposed to be a fun and exciting process.
Unfortunately, none of the ones that we saw seemed to match the specifications that we had established.
They were too small, too impersonal, too close to the neighbors.
After days of finding nothing even close, we began to wonder: was there really a perfect house out there for us?"
"The afternoon grew so glowering that in the sixth inning the arc lights were turned on--always a wan sight in the daytime, like the burning headlights of a funeral procession.
Aided by the gloom, Fisher was slicing through the Sox rookies, and Williams did not come to bat in the seventh.
He was second up in the eighth.
This was almost certainly his last time to come to the plate in Fenway Park, and instead of merely cheering, as we had at his three previous appearances, we stood, all of us, and applauded."
CSE GitLab username: sanjnamohan
Link to Git repository: https://git.cse.iitb.ac.in/sanjnamohan/outLab8
Contributions:
Sanjna Mohan (20305R006): q3
Manjusree M P (203059007): q5,q6
Pooja Gayakwad (203050076): q1,q4
Snehlata Yadav (203050075): ,q2,q7
References:
https://www.tutorialspoint.com/java/java_string_length.htm
https://www.geeksforgeeks.org/substring-in-java/
https://www.vogella.com/tutorials/JavaRegularExpressions/article.html
https://www.tutorialspoint.com/Java-String-substring-Method-example
https://stackoverflow.com/questions/3644266/how-can-we-match-an-bn-with-java-regex
https://www.w3schools.com/java/java_arraylist.asp
https://www.techiedelight.com/check-string-contains-alphanumeric-characters-java/
https://www.w3schools.com/java/java_constructors.asp
https://www.geeksforgeeks.org/passing-and-returning-objects-in-java/
https://stackoverflow.com/questions/109383/sort-a-mapkey-value-by-values
https://www.w3schools.com/java/
https://www.tutorialspoint.com/javaexamples/date_time_24hr.htm
https://www.javatpoint.com/creating-thread
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment