# 2019年58同城笔试题

(1,3,bbb)
(16,18,aaa)

(21,23,zzz)

public class Main
{
public static void main(String[] args)
{
int n = 3;
String str = "abbbccccddeeffffaaaddzzz";
int i = 0;
int j = 1;
int count;
char[] ch = str.toCharArray();
int N = ch.length - 1;
while(j<=N&&i<=N)
{
count = 1;
while(j<=N&&ch[i]==ch[j])
{
count++;
j++;

}
if(count==n)
{
System.out.print("("+i+","+(j-1)+",");
for(int k=0;k<count;k++)
{
System.out.print(ch[i]);
}
System.out.print(")");
System.out.println();
}
if(count>n)
{
i = j;
j = i + 1;
}
else
{
i = i+ 1;
j = i + 1;
}
}
}
}

[14]，[14,-2]，[14,-2,4]，[14,-2,4,3]..........

[-2]，[-2,4]，[-2,4,-3]..........

........

[22]

public class Main
{
public static void main(String[] args)
{
int[] a = {14,-2,4,-3,5,7,2,-39,22};
int N = a.length;
int Max = Integer.MIN_VALUE;		//取最小整数
int result;

for(int i=0;i<N;i++)
{
result = 0;
for(int j=i;j<N;j++)
{
result += a[j];
Max = Math.max(Max, result);
}
}
System.out.println("最大值为:"+Max);
}
}

//数组的所有连续子段的最大和
public class Main
{
public static void main(String[] args)
{
int[] a = {14,-2,4,-3,5,7,2,-39,22};
maxSum(a,a.length);
}
public static void maxSum(int[] a,int n)
{
int[] dp = new int[a.length];
dp[0] = a[0];
for(int i=1;i<n;i++)
{
dp[i] = Math.max(dp[i-1]+a[i], a[i]);
}

//System.out.println(Arrays.toString(dp));
//取出dp数组中的最大值
int max = Integer.MIN_VALUE;
for(int i=0;i<dp.length;i++)
{
if(dp[i]>max)
max = dp[i];
}
System.out.println(max);
}
}