Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make line length 88 #4768

Merged
merged 4 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 1 addition & 2 deletions content/1_General/Basic_Debugging.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ the variable (`#v`) in addition to the value of the variable (`v`).
#include <iostream>
using namespace std;

#define dbg(v) \
cout << "Line(" << __LINE__ << ") -> " << #v << " = " << (v) << endl;
#define dbg(v) cout << "Line(" << __LINE__ << ") -> " << #v << " = " << (v) << endl;

int x = 10; // pretend this variable is important

Expand Down
3 changes: 1 addition & 2 deletions content/1_General/Choosing_Lang.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ public class wormsort {
rhs = new int[m];
weight = new int[m];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++)
loc[i] = Integer.parseInt(st.nextToken()) - 1;
for (int i = 0; i < n; i++) loc[i] = Integer.parseInt(st.nextToken()) - 1;
for (int i = 0; i < m; i++) {
st = new StringTokenizer(br.readLine());
lhs[i] = Integer.parseInt(st.nextToken()) - 1;
Expand Down
6 changes: 2 additions & 4 deletions content/1_General/Fast_IO.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,7 @@ import java.util.*;
public class Solution {
static final int MOD = (int)1e9 + 7;
public static void main(String[] args) throws Exception {
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(br.readLine());
int M = Integer.parseInt(st.nextToken());
Expand Down Expand Up @@ -580,8 +579,7 @@ public class Solution {
}

public static void main(String[] args) throws Exception {
st = new StreamTokenizer(
new BufferedReader(new InputStreamReader(System.in)));
st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter pw = new PrintWriter(System.out);
int M = nextInt();
int N = nextInt();
Expand Down
6 changes: 2 additions & 4 deletions content/1_General/Generic_Code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,7 @@ template <class T> struct Point3D {
Point3D<int> p1{1, 2, 3};
Point3D<int> p2{3, 4, 5};
Point3D<double> p3{1.1, 2.2, 3.3};
Point3D<long long> p4{9223372036854775807, 9223372036854775807,
9223372036854775807};
Point3D<long long> p4{9223372036854775807, 9223372036854775807, 9223372036854775807};
```

It would be narrow-minded to think that templates are in any way limited to
Expand Down Expand Up @@ -763,8 +762,7 @@ if we want code to run differently for different versions of C++, we can write:
* "Clamps" v between the values of lo and hi if it's
* out of the bounds defined by those two values.
*/
template <class T>
constexpr const T &clamp(const T &v, const T &lo, const T &hi) {
template <class T> constexpr const T &clamp(const T &v, const T &lo, const T &hi) {
assert(lo <= hi);
if (v < lo) {
return lo;
Expand Down
3 changes: 1 addition & 2 deletions content/1_General/Input_Output.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,7 @@ following (ex.
[here](http://www.usaco.org/current/data/sol_circlecross_bronze_feb17.html)):

```java
PrintWriter pw =
new PrintWriter(new BufferedWriter(new FileWriter("problemname.out")));
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("problemname.out")));
```

This is equivalent to what we use in this module:
Expand Down
4 changes: 1 addition & 3 deletions content/1_General/Running_Code_Locally.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,7 @@ Consider this code of `Main.java` and assume it is in a file on your computer:

```java
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
public static void main(String[] args) { System.out.println("Hello World!"); }
}
```

Expand Down
6 changes: 2 additions & 4 deletions content/2_Bronze/Complete_Rec.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -810,8 +810,7 @@ public class ChessboardQueens {
private static int validNum = 0;

public static void main(String[] args) throws Exception {
BufferedReader read =
new BufferedReader(new InputStreamReader(System.in));
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
for (int r = 0; r < DIM; r++) {
String row = read.readLine();
for (int c = 0; c < DIM; c++) {
Expand Down Expand Up @@ -1012,8 +1011,7 @@ public class ChessboardQueens {
private static int validNum = 0;

public static void main(String[] args) throws Exception {
BufferedReader read =
new BufferedReader(new InputStreamReader(System.in));
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
for (int r = 0; r < DIM; r++) {
String row = read.readLine();
for (int c = 0; c < DIM; c++) {
Expand Down
9 changes: 3 additions & 6 deletions content/2_Bronze/Intro_Graphs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,8 @@ import java.util.*;

public class LineUp {
// Assumed to be in sorted order (which it is)
static final String[] COWS =
new String[] {"Beatrice", "Belinda", "Bella", "Bessie",
"Betsy", "Blue", "Buttercup", "Sue"};
static final String[] COWS = new String[] {
"Beatrice", "Belinda", "Bella", "Bessie", "Betsy", "Blue", "Buttercup", "Sue"};

public static void main(String[] args) throws IOException {
Map<String, Integer> cowInds = new HashMap<>();
Expand All @@ -204,9 +203,7 @@ public class LineUp {
int reqNum = Integer.parseInt(read.readLine());

List<Integer>[] neighbors = new ArrayList[COWS.length];
for (int c = 0; c < COWS.length; c++) {
neighbors[c] = new ArrayList<>();
}
for (int c = 0; c < COWS.length; c++) { neighbors[c] = new ArrayList<>(); }
for (int r = 0; r < reqNum; r++) {
String[] words = read.readLine().split(" ");

Expand Down
2 changes: 1 addition & 1 deletion content/2_Bronze/Intro_Sets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ set.add(1); // {1, 4, 2}
System.out.println(set.contains(1)); // true
set.remove(1); // {4, 2}
System.out.println(set.contains(5)); // false
set.remove(0); // does nothing because 0 wasn't in the set
set.remove(0); // does nothing because 0 wasn't in the set
```

### Sorted Sets
Expand Down
3 changes: 1 addition & 2 deletions content/2_Bronze/Intro_Sorting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ import java.util.*;

class Main {
public static void main(String[] args) {
List<Integer> arr =
new ArrayList<Integer>(Arrays.asList(5, 1, 3, 2, 4));
List<Integer> arr = new ArrayList<Integer>(Arrays.asList(5, 1, 3, 2, 4));
Collections.sort(arr);
System.out.println(arr); // Outputs [1, 2, 3, 4, 5]
}
Expand Down
11 changes: 4 additions & 7 deletions content/2_Bronze/Rect_Geo.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,8 @@ int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;

int total = (b - a) + (d - c); // the sum of the two intervals
int intersection =
max(min(b, d) - max(a, c), 0); // subtract the intersection
int total = (b - a) + (d - c); // the sum of the two intervals
int intersection = max(min(b, d) - max(a, c), 0); // subtract the intersection
int ans = total - intersection;

cout << ans << "\n";
Expand Down Expand Up @@ -656,8 +655,7 @@ bool intersect(vector<int> s1, vector<int> s2) {
int bl_b_x = s2[0], bl_b_y = s2[1], tr_b_x = s2[2], tr_b_y = s2[3];

// no overlap
if (bl_a_x >= tr_b_x || tr_a_x <= bl_b_x || bl_a_y >= tr_b_y ||
tr_a_y <= bl_b_y) {
if (bl_a_x >= tr_b_x || tr_a_x <= bl_b_x || bl_a_y >= tr_b_y || tr_a_y <= bl_b_y) {
return false;
} else {
return true;
Expand All @@ -672,8 +670,7 @@ boolean intersect(int[] s1, int[] s2) {
int bl_b_x = s2[0], bl_b_y = s2[1], tr_b_x = s2[2], tr_b_y = s2[3];

// no overlap
if (bl_a_x >= tr_b_x || tr_a_x <= bl_b_x || bl_a_y >= tr_b_y ||
tr_a_y <= bl_b_y) {
if (bl_a_x >= tr_b_x || tr_a_x <= bl_b_x || bl_a_y >= tr_b_y || tr_a_y <= bl_b_y) {
return false;
} else {
return true;
Expand Down
3 changes: 1 addition & 2 deletions content/2_Bronze/Simulation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ public class MixMilk {
* The amount of milk to pour is the minimum of the remaining milk
* in bucket 1 and the available capacity of bucket 2
*/
int amt =
Math.min(milk[bucket1], capacity[bucket2] - milk[bucket2]);
int amt = Math.min(milk[bucket1], capacity[bucket2] - milk[bucket2]);

milk[bucket1] -= amt;
milk[bucket2] += amt;
Expand Down
3 changes: 1 addition & 2 deletions content/3_Silver/Binary_Search.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -937,8 +937,7 @@ import java.util.*;

public class Haybales {
public static void main(String[] args) throws IOException {
BufferedReader br =
new BufferedReader(new FileReader(new File("haybales.in")));
BufferedReader br = new BufferedReader(new FileReader(new File("haybales.in")));
PrintWriter out = new PrintWriter("haybales.out");
StringTokenizer st = new StringTokenizer(br.readLine());

Expand Down
15 changes: 6 additions & 9 deletions content/3_Silver/Flood_Fill.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,7 @@ public class Floodfill {
private static int rowNum;
private static int colNum;
public static void main(String[] args) throws IOException {
BufferedReader read =
new BufferedReader(new InputStreamReader(System.in));
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
SansPapyrus683 marked this conversation as resolved.
Show resolved Hide resolved
StringTokenizer dims = new StringTokenizer(read.readLine());
rowNum = Integer.parseInt(dims.nextToken());
colNum = Integer.parseInt(dims.nextToken());
Expand Down Expand Up @@ -395,7 +394,7 @@ int curr_size = 0; // reset to 0 each time we start a new component
void floodfill(int r, int c, int color) {
if ((r < 0 || r >= row_num || c < 0 || c >= col_num) // if out of bounds
|| grid[r][c] != color // wrong color
|| visited[r][c] // already visited this square
|| visited[r][c] // already visited this square
)
return;

Expand Down Expand Up @@ -441,8 +440,7 @@ public class Floodfill {
private static int colNum; // grid dimensions, rows and columns
private static boolean[][] visited; // keeps track of which nodes have been
// visited
private static int currSize =
0; // reset to 0 each time we start a new component
private static int currSize = 0; // reset to 0 each time we start a new component

public static void main(String[] args) {
/*
Expand Down Expand Up @@ -590,8 +588,8 @@ void floodfill(int r, int c) {
c = frontier.top().second;
frontier.pop();

if (r < 0 || r >= row_num || c < 0 || c >= col_num ||
building[r][c] == '#' || visited[r][c])
if (r < 0 || r >= row_num || c < 0 || c >= col_num || building[r][c] == '#' ||
visited[r][c])
continue;

visited[r][c] = true;
Expand Down Expand Up @@ -657,8 +655,7 @@ public class RoomCount {
}

public static void main(String[] args) throws IOException {
BufferedReader read =
new BufferedReader(new InputStreamReader(System.in));
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer dims = new StringTokenizer(read.readLine());
rowNum = Integer.parseInt(dims.nextToken());
colNum = Integer.parseInt(dims.nextToken());
Expand Down
21 changes: 6 additions & 15 deletions content/3_Silver/Func_Graphs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ import java.io.*;
import java.util.*;

public class CoopGame {
static BufferedReader read =
new BufferedReader(new InputStreamReader(System.in));
static BufferedReader read = new BufferedReader(new InputStreamReader(System.in));

public static void main(String[] args) throws IOException {
moveResult(new int[] {0, 1});
Expand Down Expand Up @@ -390,15 +389,12 @@ public class Badge {
}

public static void main(String[] args) throws IOException {
BufferedReader reader =
new BufferedReader(new InputStreamReader(System.in));
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

int n = Integer.parseInt(reader.readLine());
p = new int[n];
StringTokenizer st = new StringTokenizer(reader.readLine());
for (int i = 0; i < n; i++) {
p[i] = Integer.parseInt(st.nextToken()) - 1;
}
for (int i = 0; i < n; i++) { p[i] = Integer.parseInt(st.nextToken()) - 1; }
reader.close();

ans = new int[n];
Expand All @@ -408,9 +404,7 @@ public class Badge {
dfs(i);
}

for (int i = 0; i < n - 1; i++) {
System.out.print((ans[i] + 1) + " ");
}
for (int i = 0; i < n - 1; i++) { System.out.print((ans[i] + 1) + " "); }
System.out.println(ans[n - 1] + 1);
}
}
Expand Down Expand Up @@ -580,8 +574,7 @@ public class Badge {
static List<List<Integer>> radj;

public static void main(String[] args) throws IOException {
BufferedReader in =
new BufferedReader(new InputStreamReader(System.in));
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

int n = Integer.parseInt(in.readLine());
adj = new int[n];
Expand Down Expand Up @@ -812,9 +805,7 @@ public class Badge {
int n = Integer.parseInt(st.nextToken());
arr = new int[n + 1];
st = new StringTokenizer(x.readLine());
for (int i = 1; i <= n; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
for (int i = 1; i <= n; i++) { arr[i] = Integer.parseInt(st.nextToken()); }

ans = new int[n + 1];
Arrays.fill(ans, -1);
Expand Down
8 changes: 2 additions & 6 deletions content/3_Silver/Graph_Traversal.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -999,9 +999,7 @@ int main() {
}

if (valid) {
for (int i = 0; i < n; i++) {
cout << assigned[i] << " \n"[i == n - 1];
}
for (int i = 0; i < n; i++) { cout << assigned[i] << " \n"[i == n - 1]; }
} else {
cout << "IMPOSSIBLE" << endl;
}
Expand Down Expand Up @@ -1140,9 +1138,7 @@ int main() {
end:;

if (valid) {
for (int i = 0; i < n; i++) {
cout << assigned[i] << " \n"[i == n - 1];
}
for (int i = 0; i < n; i++) { cout << assigned[i] << " \n"[i == n - 1]; }
} else {
cout << "IMPOSSIBLE" << endl;
}
Expand Down
16 changes: 8 additions & 8 deletions content/3_Silver/Greedy_Sorting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,10 @@ as `pair<end, start>`.

```cpp
// read in the input, store the events in pair<int, int>[] events.
sort(events, events + n); // sorts by first element (ending time)
int currentEventEnd = -1; // end of event currently attending
int ans = 0; // how many events were attended?
for (int i = 0; i < n; i++) { // process events in order of end time
sort(events, events + n); // sorts by first element (ending time)
int currentEventEnd = -1; // end of event currently attending
int ans = 0; // how many events were attended?
for (int i = 0; i < n; i++) { // process events in order of end time
if (events[i].second >= currentEventEnd) { // if event can be attended
// we know that this is the earliest ending event that we can attend
// because of how the events are sorted
Expand Down Expand Up @@ -339,10 +339,10 @@ static class Event implements Comparable<Event> {

```java
// read in the input, store the events in Event[] events.
Arrays.sort(events); // sorts by comparator we defined above
int currentEventEnd = -1; // end of event currently attending
int ans = 0; // how many events were attended?
for (int i = 0; i < n; i++) { // process events in order of end time
Arrays.sort(events); // sorts by comparator we defined above
int currentEventEnd = -1; // end of event currently attending
int ans = 0; // how many events were attended?
for (int i = 0; i < n; i++) { // process events in order of end time
if (events[i].start >= currentEventEnd) { // if event can be attended
// we know that this is the earliest ending event that we can attend
// because of how the events are sorted
Expand Down
Loading
Loading