枯木逢春不再茂,年少且惜镜边人
这周继续学习java
开幕雷击
package com.company;
public class zuida {
public static void main(String[] args) {
int[] a = {0, 1, 4, 6, 5, 8,8,9};
int b = a[0];
for (int i = 0; i < a.length; i++) {
if (b < a[i])
b = a[i];
}
System.out.println("最大是" + b);
}
}
简单的找最大数
数组的转置
package com.company;
public class zhuanzhi {
public static void main(String[] args) {
int[]a={0,1,2,3,4};
int j=a[a.length-1];
for(int i=0;i<(a.length/2);i++)
{
int temp=a[j];
a[j]=a[i];
a[i]=temp;
j--;
}
for (int i=0;i<a.length;i++)
System.out.println(a[i]);
}
}
面向对象(偷懒)
package com.company;
import java.util.Arrays;
public class duixiang {
public static void main(String[] args) {
int []a={0,1,2,3,4,5};
System.out.println(Arrays.toString(a));
}
}
面向过程(c语言)
package com.company;
import java.util.Arrays;
public class duixiang {
public static void main(String[] args) {
int []a={0,1,2,3,4,5};
System.out.print("[");
for (int i = 0; i < 6; i++) {
if (i == 5)
System.out.println(a[i] + "]");
else
System.out.print(a[i]);
}
}
}
看看对象中 的 堆 栈 方法区
写一个简单的 类
package domeo;
public class Phone {
String name;
int money;
public void call(String who) {
System.out.println("给"+who+"打电话");
}
public void sent() {
System.out.println("发短信");
}
}
下面就是用它
package domeo;
public class one {
public static void main(String[] args) {
Phone one =new Phone();
one.money=101;
one.name="spark";
System.out.println(one.money);
System.out.println(one.name);
one.call("qiaobusi");
one.sent();
}
}
两个对象中的内存区别
acm 第5届 校车题
#include<bits/stdc++.h>
using namespace std;
//#define int long long
const int N=1e5+5;
int a[N],b[N];
int sum[N<<1];
int xx[N<<1],num;
signed main(){
int T;cin>>T;
while(T--){
int n;cin>>n;
num=0;
for(int i=1;i<=n;i++){
cin>>a[i]>>b[i];
xx[++num]=a[i];
xx[++num]=b[i];
}
sort(xx+1,xx+1+num);
num=unique(xx+1,xx+1+num)-xx-1;
for(int i=1;i<=num;i++){
printf("%d ",xx[i]);
}
for(int i=1;i<=n;i++){
a[i]=lower_bound(xx+1,xx+1+num,a[i])-xx;
b[i]=lower_bound(xx+1,xx+1+num,b[i])-xx;
printf("%d----",a[i]);
printf("%d\n",b[i]);
}
/*for(int i=1;i<=num;i++){
sum[i]=0;
}
for(int i=1;i<=n;i++){
sum[a[i]]++;
sum[b[i]]--;
}
int ma=0;
for(int i=1;i<=num;i++){
sum[i]+=sum[i-1];
ma=max(ma,sum[i]);
}
cout<<num<<' '<<ma<<endl;
}}
return 0;
}