but it still got WA
plz help me~~
thx

Code: Select all
[cpp]
CUT
i got AC
[/cpp]
Moderator: Board moderators
Code: Select all
[cpp]
CUT
i got AC
[/cpp]
Code: Select all
static char[] word;
static Hashtable mirrors;
public static void main(String args[]) {
boolean palindrome;
boolean mirror;
mirrors = new Hashtable();
String entrada = readLn(100);
mirrors.put("A","A"); mirrors.put("E","3"); mirrors.put("H","H");
mirrors.put("I","I"); mirrors.put("J","L"); mirrors.put("M","M");
mirrors.put("O","O"); mirrors.put("S","2"); mirrors.put("T","T");
mirrors.put("U","U"); mirrors.put("V","V"); mirrors.put("X","X");
mirrors.put("W","W"); mirrors.put("Y","Y"); mirrors.put("Z","5");
mirrors.put("1","1"); mirrors.put("2","S"); mirrors.put("3","E");
mirrors.put("5","Z"); mirrors.put("8","8");
while (entrada != null && !entrada.equals("")) {
palindrome = verifyPalindrome(entrada);
mirror = verifyMirrored(entrada);
if (palindrome && mirror)
System.out.println(entrada + " -- is a mirrored palindrome.\n");
else if (palindrome)
System.out.println(entrada + " -- is a regular palindrome.\n");
else if (mirror)
System.out.println(entrada + " -- is a mirrored string.\n");
else System.out.println(entrada + " -- is a not a palindrome.\n");
entrada = readLn(255);
}
}
static boolean verifyMirrored(String input) {
word = input.toCharArray();
int last = word.length -1;
if (last == 0) // ONLY ONE CHAR;
return false;
for (int i = 0; i <= last; i++) {
String s1 = String.valueOf(word[last]);
String s2 = String.valueOf(word[i]);
String s3 = (String)mirrors.get(s2);
if (!s1.equals(s3))
return false;
last--;
}
return true;
}
static boolean verifyPalindrome(String entrada) {
word = entrada.toCharArray();
int last = word.length - 1;
for (int i = 0; i <= last / 2; i++) {
if (word[i] != word[last - i])
return false;
}
return true;
}
Output should be :NOTAPALINDROME
ISAPALINILAPASI
2A3MEAS
ATOYOTA
MAIAM
123ESI
123ES1
DEO3D
9339
A
B
E
M
1
3
2
4
Best regards.NOTAPALINDROME -- is not a palindrome.
ISAPALINILAPASI -- is a regular palindrome.
2A3MEAS -- is a mirrored string.
ATOYOTA -- is a mirrored palindrome.
MAIAM -- is a mirrored palindrome.
123ESI -- is not a palindrome.
123ES1 -- is a mirrored string.
DEO3D -- is not a palindrome.
9339 -- is a regular palindrome.
A -- is a mirrored palindrome.
B -- is a regular palindrome.
E -- is a regular palindrome.
M -- is a mirrored palindrome.
1 -- is a mirrored palindrome.
3 -- is a regular palindrome.
2 -- is a regular palindrome.
4 -- is a regular palindrome.
Code: Select all
#include<stdio.h>
#include<string.h>
int Palind(char *string)
{
int len,i;
len = strlen(string)-1;
for(i = 0;i<=len/2;i++)
{
if(string[i]!=string[len-i])
return 0;
}
return 1;
}
int Mirror(char *string)
{
char Mir[300];
Mir['A'] = 'A'; Mir['E'] = '3'; Mir['H'] = 'H'; Mir['I'] = 'I'; Mir['J'] = 'L';
Mir['M'] = 'M'; Mir['O'] = 'O'; Mir['S'] = '2'; Mir['T'] = 'T'; Mir['U'] = 'U'; Mir['V'] = 'V'; Mir['W'] = 'W'; Mir['X'] = 'X';
Mir['Y'] = 'Y'; Mir['Z'] = '5'; Mir['1'] = '1'; Mir['2'] = 'S'; Mir['3'] = 'E'; Mir['5'] = 'Z'; Mir['8'] = '8';
int len,i;
len = strlen(string)-1;
for(i = 0; i<=len/2;i++)
{
if(string[i]!=Mir[string[len-i]])
return 0;
}
return 1;
}
void main()
{
char input[30];
int m,p;
while(gets(input)!=NULL)
{
p = Palind(input);
m = Mirror(input);
if(!p)
{
if(!m)
printf("%s -- is not a palindrome.\n\n",input);
else
printf("%s -- is a mirrored string.\n\n",input);
}
else
{
if(!m)
printf("%s -- is a regular palindrome.\n\n",input);
else
printf("%s -- is a mirrored palindrome.\n\n",input);
}
}
}
//Plz help meeeee............[/b]
Code: Select all
I GOT IT AC .DELETED