摘要:
编写一个visualcount类支持+1和-1操作,它的构造函数接受2个参数,N,Max。 其中N指定了操作的最大次数,Max指定了计数器的最大绝对值.作为副作用,用图像显示每次作用后最大的值 import edu.princeton.cs.algs4.StdDraw; import edu.pri 阅读全文
摘要:
设a[],b[]都是长为数百万的数组 int[] t = a; a=b; b = t; 这段代码会将他们交换。它的效率不可能再高了, 因为它交换的是引用,而不是数百万个元素。 例子如下: import edu.princeton.cs.algs4.StdOut; public class No_1_ 阅读全文
摘要:
题目:如果字符s中的字符循环移动任意位置之后可以得到另一个字符t,那么s就被t称为回环变位。例如:ACTGAC 就是 TGACAC的一个回环变位,反之亦然; 代码如下: import edu.princeton.cs.algs4.StdOut; public class No1_2_5 { publ 阅读全文
摘要:
题目: 编写一个Interval2D的用例,从命令行接收参数n,min,max的输入;生成n个随机的2D间隔, 其宽和高均匀的分布在单位正方形中的min,和max之间。用StdDraw画出它们,并打印出相交的间隔数量; ac代码如下:(注意我没有用命令行输入,我用的是eclipse输入) impor 阅读全文
摘要:
public class Binarysearch { public static int rank(int key,int[] a) { return rank(key,a,0,a.length-1); } public static int rank(int key,int[] a,int lo 阅读全文
摘要:
递归有三个基本点: 1.递归总有一个最简单的情况。即边界或者跳出递归的条件语句; 2.递归总是尝试解决一个规模更小的问题; 3.递归尝试解决的父问题和子问题之间不因该有交集; 以下是几个递归代码://斐波那契数列 import edu.princeton.cs.algs4.StdOut; publi 阅读全文
摘要:
import edu.princeton.cs.algs4.*; public class No_1_1_13 { public static void main(String[] args) { int m=4; int n=3; int [][] a = new int[m][n]; for(i 阅读全文
摘要:
给定 N 个正整数,要求你从中得到下列三种计算结果: A1 = 能被 3 整除的最大整数 A2 = 存在整数 K 使之可以表示为 3K+1 的整数的个数 A3 = 存在整数 K 使之可以表示为 3K+2 的所有整数的平均值(精确到小数点后 1 位) 输入格式: 输入首先在第一行给出一个正整数 N,随 阅读全文
摘要:
//关于typedef //1.在c语言中定义一个结构体typedef struct student{ int a;}stu;//typedef 给结构体起了个别名 stu;//于是,在声明变量的时候就可以用: stu stu1;//如果没有typedef语句,就必须使用 struct studen 阅读全文
摘要:
Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, given Is PAT&TAP symmetric?, the longest symme 阅读全文
摘要:
Given any string of N (≥) characters, you are asked to form the characters into the shape of U. For example, helloworld can be printed as: h d e l l r 阅读全文
摘要:
Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1 = { 11, 12, 13, 14 } is 1 阅读全文
摘要:
People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, wher 阅读全文
摘要:
A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number 阅读全文
摘要:
A Digital Library contains millions of books, stored according to their titles, authors, key words of their abstracts, publishers, and published years 阅读全文
摘要:
An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the 阅读全文
摘要:
Given a tree, you are supposed to list all the leaves in the order of top down, and left to right. Input Specification: Each input file contains one t 阅读全文
摘要:
A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number 阅读全文
摘要:
Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to ou 阅读全文