Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit e57d9ab

Browse files
authored
Add files via upload
1 parent 11829c9 commit e57d9ab

21 files changed

+1909
-0
lines changed

beads.java

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
TASK:beads
3+
ID:johnath6
4+
LANG:JAVA
5+
PROG:beads
6+
*/
7+
8+
9+
import java.io.*;
10+
11+
public class beads {
12+
13+
public static void main(String[] args) throws IOException {
14+
BufferedReader f=new BufferedReader(new FileReader("beads.in"));
15+
PrintWriter pw=new PrintWriter(new FileWriter("beads.debug"));
16+
final int N=Integer.parseInt(f.readLine());
17+
String beads=f.readLine();
18+
String current="USA";
19+
int bit=23;//23 for beta
20+
String a=Character.toString(beads.charAt(0));
21+
int max=0;
22+
int prev=0;
23+
boolean s=true;
24+
boolean second=true;
25+
String thew="";
26+
for(int j=bit;j<N;j++) {
27+
current=Character.toString(beads.charAt(j));
28+
29+
pw.print("DEBUG: ");
30+
pw.println(current.equals("w"));
31+
if((a.equals("w"))) {
32+
33+
if(current.equals(thew)||thew.equals("")) {
34+
a=current;
35+
max++;
36+
}
37+
38+
}
39+
else if(a.equals(current)){
40+
max++;//same
41+
} else if(current.equals("w")) {
42+
43+
thew=a;//assign
44+
a="w";
45+
max++;
46+
47+
}
48+
else {
49+
if(!(second)) {
50+
second=true;
51+
thew="";
52+
System.out.print("|");
53+
if(max>prev) {
54+
prev=max;
55+
max=0;
56+
}
57+
58+
59+
}else {
60+
second=false;
61+
}
62+
if(s&&j==N-1) {
63+
pw.println("DEBUG signal 1");
64+
s=!(s);
65+
j=0;
66+
thew="";
67+
}else if(!(s)) {
68+
break;
69+
}
70+
a=current;
71+
}
72+
System.out.print(current);
73+
74+
75+
76+
}
77+
System.out.println(prev);
78+
pw.close();
79+
f.close();
80+
}
81+
}

beadsold.java

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
TASK:beads
3+
ID:johnath6
4+
LANG:JAVA
5+
PROG:beads
6+
*/
7+
8+
9+
import java.io.*;
10+
11+
public class beadsold {
12+
13+
public static void main(String[] args) throws IOException {
14+
BufferedReader f=new BufferedReader(new FileReader("beads.in"));
15+
int N=Integer.parseInt(f.readLine());
16+
String beads=f.readLine();
17+
boolean loopagain=true;
18+
String current="";
19+
String a=Character.toString(beads.charAt(0));
20+
int max=0;
21+
int prev=0;
22+
boolean again=true;
23+
boolean condtion;
24+
int debuglevel=0;
25+
for(int j=0;j<N;j++) {
26+
a="!";
27+
for(int i=j;i<N;i++) {
28+
current=Character.toString(beads.charAt(i));
29+
System.out.print(i);
30+
31+
condtion=true;
32+
if(!(current.equals("w")||max==0)&&a.equals("!")) {
33+
debuglevel=2;
34+
condtion=current.equals(a)||current.equals("w");
35+
if(again==false&&i==0) {
36+
debuglevel=1;
37+
condtion=condtion||Character.toString(beads.charAt(N-1)).equals("w");
38+
}
39+
}else if(i!=0) {
40+
condtion=condtion||a.equals("w");
41+
debuglevel=3;
42+
}else if(a.equals("csdfd")){
43+
condtion=true;
44+
}
45+
System.out.println(" "+condtion+"\t"+debuglevel+"\t"+a);
46+
if(condtion) {
47+
max++;
48+
49+
//System.err.println("found");
50+
//System.out.println(current+" "+max);
51+
52+
53+
}else if(loopagain){
54+
a=current;
55+
loopagain=false;
56+
max++;
57+
58+
59+
}else {
60+
61+
62+
if(max>prev) {
63+
prev=max;
64+
max=0;
65+
}
66+
67+
loopagain=true;
68+
a=current;
69+
System.out.println("NEW");
70+
System.out.println("RESULT: "+max);
71+
max=0;
72+
if(again==false) {
73+
break;
74+
}
75+
76+
77+
78+
}
79+
if(i==(beads.length()-1)&&again) {
80+
i=0;
81+
//System.err.println("Debug: Reloop");
82+
again=false;
83+
}
84+
}
85+
again=true;
86+
debuglevel=0;
87+
88+
}
89+
90+
91+
92+
93+
System.out.println(prev);
94+
f.close(); }}
95+

citystate.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
6
2+
MIAMI FL
3+
DALLAS TX
4+
FLINT MI
5+
CLEMSON SC
6+
BOSTON MA
7+
ORLANDO FL

citystate.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import java.io.*;
2+
import java.util.*;
3+
public class citystate {
4+
public static double decify(int num) {
5+
return 0.01*num;
6+
}
7+
public static void main(String[] args) throws Exception {
8+
// TODO Auto-generated method stub
9+
BufferedReader f=new BufferedReader(new FileReader("citystate.in"));
10+
PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("citystate.out")));
11+
double c1,c2;
12+
int N=Integer.parseInt(f.readLine());
13+
String[] state=new String[N];//INIT storage for state
14+
String[] city=new String[N];//INIT storage for city
15+
ArrayList<String> hitstates=new ArrayList<String>();
16+
ArrayList<String> hitcities=new ArrayList<String>();
17+
StringTokenizer st;
18+
for(int i=0;i<N;i++) {
19+
st=new StringTokenizer(f.readLine());
20+
state[i]=st.nextToken();
21+
city[i]=st.nextToken();
22+
//System.out.println("READ");
23+
24+
}
25+
int a,b,c,d,e;
26+
e=0;
27+
for(int i=0;i<N;i++) {
28+
a=((int) city[i].charAt(0)) -(int) ' ';
29+
b=((int) city[i].charAt(1))-(int) ' ';
30+
c1=(((double)a)+(decify(b)));
31+
for(int j=i+1;j<N;j++) {
32+
if(j==i) {
33+
continue;
34+
}
35+
c=((int) state[j].charAt(0))-(int) ' ';
36+
d=((int) state[j].charAt(1))-(int) ' ';
37+
c2=(((double)c)+decify(d));
38+
39+
//System.out.println("Debug "+c1+" , "+c2+" "+state[j].charAt(0)+state[j].charAt(1)+" "+city[i].charAt(0)+city[i].charAt(1));
40+
if(c2==c1) {
41+
42+
//System.out.println("HIT");
43+
//System.out.println(city[i]+" "+state[j]+" "+city[j]+" "+state[i]);
44+
if(city[j].equals(state[i].substring(0, 2))){
45+
e++;
46+
}
47+
}
48+
}
49+
}
50+
//String a1,a2;
51+
52+
53+
pw.println(e);
54+
pw.close();
55+
f.close();
56+
}
57+
58+
59+
}

citystate.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

citystate2.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import java.io.*;
2+
import java.util.*;
3+
public class citystate2 {
4+
5+
public static void main(String[] args) throws Exception {
6+
// TODO Auto-generated method stub
7+
BufferedReader f=new BufferedReader(new FileReader("custom.in"));
8+
PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("citystate.out")));
9+
10+
int N=Integer.parseInt(f.readLine());
11+
String[] state=new String[N];//INIT storage for state
12+
String[] city=new String[N];//INIT storage for city
13+
ArrayList<String> hitstates=new ArrayList<String>();
14+
ArrayList<String> hitcities=new ArrayList<String>();
15+
StringTokenizer st;
16+
for(int i=0;i<N;i++) {
17+
st=new StringTokenizer(f.readLine());
18+
state[i]=st.nextToken();
19+
city[i]=st.nextToken();
20+
//System.out.println("READ");
21+
22+
}
23+
int e;
24+
e=0;
25+
for(int i=0;i<N;i++) {
26+
27+
28+
for(int j=0;j<N;j++) {
29+
if(j==i) {
30+
continue;
31+
}
32+
33+
34+
//System.out.println("Debug "+c1+" , "+c2+" "+state[j].charAt(0)+state[j].charAt(1)+" "+city[i].charAt(0)+city[i].charAt(1));
35+
if(city[i].equals(state[j].substring(0, 2))) {
36+
e++;
37+
//System.out.println("HIT");
38+
hitcities.add(city[j]);
39+
hitstates.add(state[i]);
40+
}
41+
}
42+
}
43+
int cancel=0;
44+
45+
for(int i=0;i<hitstates.size();i++) {
46+
47+
48+
49+
50+
//System.out.println(" "+hitstates.get(i).charAt(0)+hitstates.get(i).charAt(1)+" "+hitcities.get(i).charAt(0)+hitcities.get(i).charAt(1));
51+
52+
if(hitcities.get(i).equals(hitstates.get(i).substring(0, 2))) {
53+
cancel++;
54+
//System.out.println("HIT");
55+
56+
}else {
57+
e--;
58+
}
59+
60+
}
61+
e=e-cancel/2;
62+
pw.println(e);
63+
pw.close();
64+
f.close();
65+
}
66+
67+
68+
}

citystate3.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import java.io.*;
2+
import java.util.*;
3+
public class citystate3 {
4+
public static double decify(int num) {
5+
return 0.01*num;
6+
}
7+
public static void main(String[] args) throws Exception {
8+
// TODO Auto-generated method stub
9+
BufferedReader f=new BufferedReader(new FileReader("citystate.in"));
10+
PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("citystate.out")));
11+
12+
13+
int N=Integer.parseInt(f.readLine());
14+
15+
String tmpStr;
16+
int [][] freq =new int[26*26][26*26];
17+
int [] idx1 = new int[N];
18+
int state, city;
19+
int Nidx=0;
20+
21+
StringTokenizer st;
22+
for(int i=0;i<N;i++) {
23+
st=new StringTokenizer(f.readLine());
24+
tmpStr=st.nextToken();
25+
state=26*(tmpStr.charAt(0)-'A')+tmpStr.charAt(1)-'A';
26+
tmpStr=st.nextToken();
27+
city=26*(tmpStr.charAt(0)-'A')+tmpStr.charAt(1)-'A';
28+
29+
if(city!=state)
30+
{
31+
if(freq[city][state]==0)
32+
idx1[Nidx++]=(city<<10)+state;
33+
freq[city][state]++;
34+
}
35+
36+
//System.out.println("READ");
37+
}
38+
int count=0;
39+
/*
40+
for(int i=0;i<26*26;i++)
41+
{
42+
for(int j=i+1;j<26*26;j++)
43+
{
44+
45+
count+=freq[i][j]*freq[j][i];
46+
}
47+
}*/
48+
49+
for(int i=0;i<Nidx;i++)
50+
{
51+
city=idx1[i]>>10;
52+
state=idx1[i]&1023;
53+
54+
//System.out.println("city:"+city+" state:"+state +" " +idx1[i]);
55+
count+=freq[city][state]*freq[state][city];
56+
57+
}
58+
59+
pw.println(count/2);
60+
pw.close();
61+
f.close();
62+
}
63+
64+
65+
}

0 commit comments

Comments
 (0)