当前位置:网站首页>OR62 倒置字符串
OR62 倒置字符串
2022-07-29 21:49:00 【syc596】
OR62 倒置字符串
import java.util.*;
public class Main {
public static void reverse(char[] ch,int left,int right){
while(left<right){
char tmp=ch[left];
ch[left]=ch[right];
ch[right]=tmp;
left++;
right--;
}
}
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
String str=sc.nextLine();
char ch[]=str.toCharArray();
reverse(ch,0,ch.length-1);
int i=0;
while(i<ch.length){
int j=i;
while(j<ch.length&&ch[j]!=' '){
j++;
}
reverse(ch,i,j-1);
if(j<ch.length){
i=j+1;
}else{
i=j;
}
}
String ret=new String(ch);
System.out.println(ret);
}
}
}
边栏推荐
猜你喜欢
新库上线 | CnOpenData国际货运代理信息数据
线性回归的多种实现方式
D. Rain(思维/线性代数/差分数组)
Add obsolete flag to pdf
GBASE 8s 数据库复合索引
中科院TextMind(文心)安装及使用
iNFTnews | 福布斯的Web3探索
《nlp入门+实战:第七章:pytorch中数据集加载和自带数据集的使用》
php反序列化结构知识点实例分析
HMS Core audio editing service audio source separation and spatial audio rendering, helping to quickly enter the world of 3D audio
随机推荐
Xshell 7 提示 “要继续使用此程序,您必须应用最新的更新或使用新版本”
GBASE 8s 数据库的恢复
对不起,你很难赚到中年人的钱
GBASE 8s PAM插入式身份验证模块
动态规划专题
The implementation of the flood control project and safety construction project in the flood storage and detention areas in Luluze and Ningjinbo was launched
lambda表达式
E. XOR Tree(树形dp/异或/最近公共祖先)
新库上线 | CnOpenData租赁和商务服务业工商注册企业基本信息数据
GBASE 8s 数据库的智能大对象备份
GBASE 8s 如何通过脚本获取bufwait等统计信息
程序员「小镇做题」出身,月薪是父母半年收入 ……
普洛斯荣获两项“数据中心绿色等级评估”5A级认证
GBASE 8s 数据库唯一索引
GTK在drawable区域绘图
外文论文的格式规范要求有哪些?
Small program WeChat positioning is not accurate
三、HikariCP源码分析之获取连接流程三
八、HikariCP源码分析之ConcurrentBag一
jsonArray中按某字段排序