微软100题-天天做-第25题
来源:互联网 发布:跑跑卡丁车淘宝好便宜 编辑:程序博客网 时间:2024/06/07 08:39
第25题(字符串):
写一个函数,它的原形是int continumax(char *outputstr,char *intputstr)
功能:
在字符串中找出连续最长的数字串,并把这个串的长度返回,
并把这个最长数字串付给其中一个函数参数outputstr所指内存。
例如:"abcd12345ed125ss123456789"的首地址传给intputstr后,函数将返回9,
写一个函数,它的原形是int continumax(char *outputstr,char *intputstr)
功能:
在字符串中找出连续最长的数字串,并把这个串的长度返回,
并把这个最长数字串付给其中一个函数参数outputstr所指内存。
例如:"abcd12345ed125ss123456789"的首地址传给intputstr后,函数将返回9,
outputstr所指的值为123456789
package com.microsoft;import java.util.ArrayList;import java.util.List;public class NumberFromString {private String str;public NumberFromString(String str){this.str=str;}public String getLongestNumberFromString(){List<String> numberList=new ArrayList<String>();char[]charArray=str.toCharArray();int start=0;int end=0;for(int i=0;i<charArray.length;i++){if(charArray[i]>='0'&&charArray[i]<='9'){start=i;int step=start+1;while(true){if(step>=str.length()){break;}if(!(charArray[step]>='0'&&charArray[step]<='9')){break;}step++;}i=step;String numberStr=str.substring(start, step);numberList.add(numberStr);}}int maxLength=0;String ret=null;for(int i=0;i<numberList.size();i++){String s=numberList.get(i);if(maxLength<s.length()){maxLength=s.length();ret=s;}}return ret;}public static void main(String[] args) {NumberFromString instance=new NumberFromString("1abc345699k99999");System.out.println(instance.getLongestNumberFromString());}}
0 0
- 微软100题-天天做-第25题
- 微软面试100题-天天做-第5题
- 微软面试100题-天天做-第6题
- 微软100题-天天做-第7题
- 微软100题-天天做-第8题
- 微软100题-天天做-第9题
- 微软100题-天天做-第10题
- 微软100题-天天做-第11题
- 微软100题-天天做-第12题
- 微软100题-天天做-第13题
- 微软100题-天天做-第14题
- 微软100题-天天做-第15题
- 微软100题-天天做-第16题
- 微软100题-天天做-第17题
- 微软100题-天天做-第18题
- 微软100题-天天做-第19题
- 微软100题-天天做-第20题
- 微软100题-天天做-第21题
- Android开发之如何保证Service不被杀掉(broadcast+system/app)
- 批处理 Bat文件编写
- wireshark---- Lua: Error during loading: [string "/usr/share/wireshark/init.lua"]:45问题解决
- oracle创建用户
- 题目1084:整数拆分
- 微软100题-天天做-第25题
- ARM常用汇编指令
- poj 3253
- GAE上部署micolog
- MySQL 存储过程的基本用法
- OpenGL使用混合来实现半透明效果 .
- C#中简单的绘图
- 英语宾语从句 引导词的选择
- 一步步学习微软InfoPath2010和SP2010--第三章节--表单设计基础:处理InfoPath布局、控件和视图(5)--理解数据绑定的基础