标签:
| 描述 |
样例输出 输出123058789,函数返回值9 输出54761,函数返回值5
接口说明 函数原型: unsignedint Continumax(char** pOutputstr, char* intputstr) 输入参数: 输出参数: 返回值:
|
|---|---|
| 知识点 | 位运算 |
| 运行时间限制 | 10M |
| 内存限制 | 128 |
| 输入 |
输入一个字符串。 |
| 输出 |
输出字符串中最长的数字字符串和它的长度。 如果数字字符串为空,则只输出0 如 input: dadfsaf output:0 |
| 样例输入 | abcd12345ed125ss123058789 |
| 样例输出 | 123058789,9 |
package com.oj5;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String str = in.nextLine();
int[] length = new int[str.length()];
int[] begin = new int[str.length()];
int pos = 0;
int count = 0;
boolean beginflag = false;
for(int i = 0;i < str.length(); i++)
if(str.charAt(i)<=‘9‘&&str.charAt(i)>=‘0‘&&beginflag==false){
beginflag = true;
count++;
begin[pos] = i;
}else if(str.charAt(i)<=‘9‘&&str.charAt(i)>=‘0‘){
count++;
}else if(beginflag==true&&(str.charAt(i)<‘0‘||str.charAt(i)>‘9‘)){
length[pos++] = count;
count = 0;
beginflag = false;
}
if(beginflag==true)
length[pos++] = count;
int max = 0;
for(int i = 0;i < pos; i++)
if(length[i]>max)
max = length[i];
if(max==0){
System.out.println(0);
return ;
}
for(int i = 0;i < pos; i++)
if(length[i]==max){
for(int j = begin[i];j < begin[i]+length[i]; j++)
System.out.print(str.charAt(j));
System.out.print(",");
}
System.out.print(max+"\n");
}
}
标签:
原文地址:http://www.cnblogs.com/lxk2010012997/p/5402147.html