当前位置:网站首页>OJ daily practice - delete word suffixes

OJ daily practice - delete word suffixes

2022-06-22 23:33:00 KJ. JK

Problem description :

Given a word , If the word follows er、ly perhaps ing The suffix ends , Delete the suffix ( Make sure that the length of the word after deleting the suffix is not 0), Otherwise, no operation will be carried out .

Input
The input line , Contains a word ( There is no space between words , The maximum length of each word is 32).

Output
Output the word according to the question .

Examples

Input
clearly

Output
clear


Java Code :

import java.util.Scanner;
public class Main {
    
public static void main(String[] args) {
    
	Scanner in=new Scanner(System.in);
	String a=in.next();
	char a1[]=a.toCharArray();
	int i=a1.length;
	if(a1[i-1]=='y'&&a1[i-2]=='l'){
    
		for(int j=0;j<a1.length-2;j++) {
    
			System.out.print(a1[j]);
		}
	}	
	else if(a1[i-1]=='r'&&a1[i-2]=='e'){
    
		for(int j=0;j<a1.length-2;j++) {
    
			System.out.print(a1[j]);
		}
	}	
	else if(a1[i-1]=='g'&&a1[i-2]=='n'&&a1[i-3]=='i'){
    
		for(int j=0;j<a1.length-3;j++) {
    
			System.out.print(a1[j]);
		}
	}
	else {
    
		System.out.print(a);
	}
}
}

author :KJ.JK
If the article is helpful to you , Welcome to praise or star, Your support is the greatest encouragement to the author , The shortcomings can be corrected in the comments section , Communication and learning

原网站

版权声明
本文为[KJ. JK]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206222059454777.html