“666”是一种网络用语,大概是表示某人很厉害、我们很佩服的意思。最近又衍生出另一个数字“9”,意思是“6翻了”,实在太厉害的意思。如果你以为这就是厉害的最高境界,那就错啦 —— 目前的最高境界是数字“27”,因为这是 3 个 “9”!
本题就请你编写程序,将那些过时的、只会用一连串“6666……6”表达仰慕的句子,翻译成最新的高级表达。
输入格式:
输入在一行中给出一句话,即一个非空字符串,由不超过 1000 个英文字母、数字和空格组成,以回车结束。
输出格式:
从左到右扫描输入的句子:如果句子中有超过 3 个连续的 6,则将这串连续的 6 替换成 9;但如果有超过 9 个连续的 6,则将这串连续的 6 替换成 27。其他内容不受影响,原样输出。
输入样例:
it is so 666 really 6666 what else can I say 6666666666
输出样例:
it is so 666 really 9 what else can I say 27
代码:
package com.southwind;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
// 从左到右扫描输入的句子:如果句子中有超过 3 个连续的 6,则将这串连续的 6 替换成 9;
// 但如果有超过 9 个连续的 6,则将这串连续的 6 替换成 27。其他内容不受影响,原样输出。
//it is so 666 really 6666 what else can I say 6666666666
//it is so 666 really 9 what else can I say 27
public class sixsixsix {
public static void main(String[] args) throws IOException {
//String s1 = "it is so 666 really 6666 what else can I say 666666666";
Scanner sc = new Scanner(System.in);
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
String str = buffer.readLine();
getResult(str);
}
public static void getResult(String str)
{
char a[] =str.toCharArray();
String result="";
int i = 0;
int six_num = 0;
for(i=0;i<a.length;i++)
{
//当有6就加1
if(a[i]=='6')
six_num++;
else
{
if(six_num==0)
{
System.out.print(a[i]);
continue;
}
else if(six_num<4)
{
for(int j=1;j<=six_num;j++)
System.out.print('6');
System.out.print(a[i]);
}
else if(six_num<10)
System.out.print("9"+a[i]);
else
{
System.out.print("27"+a[i]);
}
six_num=0;
}
}
if(six_num>=9)
System.out.print("27");
else if(six_num>3)
System.out.print("9");
else if(six_num>0)
{
while(six_num>0) {
System.out.print("6");
six_num--;
}
}
}
}