import?java.util.*;
public?class?Huiwen2?{
public?static?void?main(String[]?args){
Stack<String>?s=new?Stack<String>();?
@SuppressWarnings("resource")
Scanner?input=new?Scanner(System.in);
System.out.println("輸入一串字符,以#結束:");
String?s1=(String)?input.nextLine();
while(s1.charAt(s1.length()-1)!='#'){
System.out.println("請以#為結尾,重新輸入:");
s1=input.nextLine();}
?????for(int?i=0;i<s1.length();i++){
s.push(s1);
?????}
s.pop();
Queue<String>?q=new?LinkedList<String>?();
for(int?i=0;i<s1.length();i++){
q.offer(s1);
?????}
/**/
String?str0=new?String();
String?str1=new?String();
String?str2=new?String();
int?i=0,flag=0;
while?(i<str0.length())?
{
q.offer(str0.substring(i,i+1));???
s.push(str0.substring(i,i+1));???
i++;
}?
System.out.println(q.toString());
System.out.println(s.toString());
while?(!s.empty())
{
str1=q.poll();
str2=s.pop();
if?(!str1.equals(str2))
????????????????????????{
?????flag=1;
?????????????????????????????break;
}
}
System.out.println(q.toString());
System.out.println(s.toString());
/**/
if(q.poll()==s.pop()){
System.out.println("回文");
}
else{System.out.println("不是回文");}
}
}
有個妹子問我,以我的能力改不了這個代碼。
這個代碼好像還有異常產生。有沒有大神幫我改一下,再給我簡單講一下。
在下感激不盡。。。求大神指教
添加回答
舉報
0/150
提交
取消