剑指offer第二题替换空格 不用replace
来源:互联网 发布:中国工业企业数据库 编辑:程序博客网 时间:2024/06/08 11:58
package fenshujs;
import java.util.Scanner;
public class Janzhioffer {
/*
* 剑指offer第二题 替换空格
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
char[] a = sc.nextLine().toCharArray();
int count = 0;
for(int i = 0;i<a.length;i++)
{
if(a[i] == 32)
{
count++;
}
}
char[] b = new char[a.length+count*2];
int p2 = b.length-1;
for(int i = a.length-1;i>=0;i--)
{
if(a[i] != 32)
{
b[p2] = a[i];
}
else
{
b[p2] = '0';
b[--p2] = '2';
b[--p2] = '%';
}
p2--;
}
System.out.println(b);
}
import java.util.Scanner;
public class Janzhioffer {
/*
* 剑指offer第二题 替换空格
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
char[] a = sc.nextLine().toCharArray();
int count = 0;
for(int i = 0;i<a.length;i++)
{
if(a[i] == 32)
{
count++;
}
}
char[] b = new char[a.length+count*2];
int p2 = b.length-1;
for(int i = a.length-1;i>=0;i--)
{
if(a[i] != 32)
{
b[p2] = a[i];
}
else
{
b[p2] = '0';
b[--p2] = '2';
b[--p2] = '%';
}
p2--;
}
System.out.println(b);
}
}
We Are Happy
We%20Are%20Happy
阅读全文
0 0
- 剑指offer第二题替换空格 不用replace
- 剑指offer第二题替换空格
- 剑指offer第二题:替换空格结题报告
- 剑指offer第二题【替换空格】c++实现
- 剑指offer第二题 替换空格 Java实现
- [剑指offer]替换空格
- [剑指offer]替换空格
- 剑指offer:替换空格
- 替换空格--《剑指offer》
- 剑指Offer:替换空格
- 【剑指offer】替换空格
- 《剑指Offer》--替换空格
- 剑指offer--替换空格
- 【剑指offer】替换空格
- 【剑指offer】空格替换
- 剑指offer-替换空格
- 剑指offer:替换空格
- [剑指offer]替换空格
- 基于RPGMakerMV的JavaScript基础-3
- 消息中间件activeMq ------------开篇(一)
- SQL Server 2008R2 Express 登录模式修改
- hbase 替换 mysql
- 计算机网络常见问题
- 剑指offer第二题替换空格 不用replace
- 关于C语言里格式化小数输出
- 文章标题
- hdu6199
- LeetCode Two Sum
- lnmp配置ftp及权限操作的简单记录
- python-层次聚类算法实例-仅针对连续性变量
- 154. Find Minimum in Rotated Sorted Array II
- 通过ApplicationContextAware加载Spring上下文环境(获取bean)