在字符串中找出连续最长的数字串
2016-04-17 20:55
239 查看
描述 | 样例输出 输出123058789,函数返回值9 输出54761,函数返回值5 接口说明 函数原型: unsignedint Continumax(char** pOutputstr, char* intputstr) 输入参数: char* intputstr 输入字符串; 输出参数: char** pOutputstr: 连续最长的数字串,如果连续最长的数字串的长度为0,应该返回空字符串;如果输入字符串是空,也应该返回空字符串; 返回值: 连续最长的数字串的长度 |
---|---|
知识点 | 位运算 |
运行时间限制 | 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"); } }
相关文章推荐
- arcgis api for javascript中使用proxy.jsp
- 20145225《Java程序设计》 第7周学习总结
- WEB API 系列(二) Filter的使用以及执行顺序
- JAVA五周作业
- 第五次作业
- sql执行顺序
- 如何预测一个互联网产品的未来—一套关于产品的数学模型
- 如何保存微信视频到本地,微信朋友圈怎么发本地的视频。
- java实现 二叉树的深度&判断二叉树是否是平衡二叉树
- 第四周项目四(1)-程序分析
- GGRecovery 下载与使用方法
- hdu-2157 How many ways??(矩阵快速幂)
- 夺命雷公狗---Thinkphp----9之中间层的创建,防止跨目录访问
- View的点击事件
- 经典励志对句
- 如何在android使用face++(Android Studio)
- Ruby七日谈.第二夜—面向对象
- 用Eclipse追PostgreSQL源码
- XML介绍
- LeetCode *** 63. Unique Paths II