Skip to content

Instantly share code, notes, and snippets.

@tombrad
tombrad / gist:4697060
Last active March 14, 2024 15:50
8.4 Open the file romeo.txt and read it line by line. For each line, split the line into a list of words using the split() function. The program should build a list of words. For each word on each line check to see if the word is already in the list and if not append it to the list. When the program completes, sort and print the resulting words …
fname = raw_input("Enter file name: ")
fh = open(fname)
lst = list() # list for the desired output
for line in fh: # to read every line of file romeo.txt
word= line.rstrip().split() # to eliminate the unwanted blanks and turn the line into a list of words
for element in word: # check every element in word
if element in lst: # if element is repeated
continue # do nothing
else : # else if element is not in the list
lst.append(element) # append
@chanwit
chanwit / No1.java
Created October 26, 2013 06:01
เฉลย Lab 4 กลุ่ม 1
package oot.lab4.group1;
import java.util.Scanner;
public class No1 {
public static int[] genArrayA(int num) {
int[] a = new int[num];
int n = 0;
int i = 0;
@dlfigueira
dlfigueira / CS101Class
Created June 20, 2014 09:27
Challenge #167 [Intermediate] Final Grades
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[][] array = new int[in.nextInt()][in.nextInt()];
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
@eMahtab
eMahtab / TwoDArrayInput.java
Created November 19, 2015 13:12
Java program to take 2D array as input from user.
import java.util.Scanner;
public class TwoDArrayInput{
public static void main(String args[]){
System.out.print("Enter 2D array size : ");
Scanner sc=new Scanner(System.in);
int rows=sc.nextInt();
int columns=sc.nextInt();
@chanwit
chanwit / lab4_1 No1.java
Created December 12, 2015 10:02
เฉลย Lab 4 (OOT 58)
package oot.lab4.group1.y58;
import java.util.Scanner;
public class No1 {
public static int[] genArrayA(int size) {
int[] a = new int[size];
int n = 20;
int i = 0;
@quickgrid
quickgrid / cppBfsGraphTraversalShortestPathImplementation.cpp
Created May 26, 2016 19:44
C++ easy Graph BFS Traversal with shortest path finding for undirected graphs and shortest path retracing thorough parent nodes.
/**
* Author: Asif Ahmed
* Site: http://quickgrid.blogspot.com
* Description: C++ easy Graph BFS Traversal with shortest path finding for undirected graphs
* and shortest path retracing thorough parent nodes.
*/
#include<bits/stdc++.h>
using namespace std;
package sdk.algo;
import java.util.Arrays;
import java.util.Scanner;
/**
* http://59.23.113.171/pool/koi_budget/koi_budget.php?pname=koi_budget
* 더블릿, 예산
*
* @author whitebeard
@MichelleDalalJian
MichelleDalalJian / py4e_ex_08_05
Created October 7, 2017 12:54
8.5 Open the file mbox-short.txt and read it line by line. When you find a line that starts with 'From ' like the following line: From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008 You will parse the From line using split() and print out the second word in the line (i.e. the entire address of the person who sent the message). Then print out…
fhand = open("mbox-short.txt")
count = 0
for line in fhand:
line = line.rstrip()
if line == "": continue
words = line.split()
if words[0] !="From": continue
print(words[1])
@luchtech
luchtech / PhotoCopier.java
Created August 21, 2018 07:24
Real-Life Processes (Constructors, Setters, Getters)
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;