Code: Select all
At last ACC. i think i should be more watchful about code. :roll:
Moderator: Board moderators
Code: Select all
At last ACC. i think i should be more watchful about code. :roll:
Code: Select all
import java.util.Scanner;
class Main {
static boolean vowel (char ch) {
if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') return true;
return false;
}
public static void main (String args[]) {
Scanner input = new Scanner(System.in);
int L, N, i, j, k;
String irregular[] = new String [25];
String plural[] = new String [25];
String word[] = new String [25];
L = input.nextInt();
N = input.nextInt();
for(i=0; i<L; i++) {
irregular[i] = input.next();
plural[i] = input.next();
}
for(i=0; i<N; i++)
word[i] = input.next();
for(i=0; i<N; i++) {
for(k=0; k<L; k++) {
if(word[i].compareTo(irregular[k]) == 0) {
System.out.println(plural[k]);
break;
}
}
if(k == L) {
int len = word[i].length();
if(word[i].charAt(len-1) == 'y' && len > 1 && !vowel(word[i].charAt(len-2))) {
for(j=0; j<len-1; j++)
System.out.print(word[i].charAt(j));
System.out.println("ies");
}
else if (word[i].charAt(len-1) == 'o' || word[i].charAt(len-1) == 's' || word[i].charAt(len-1) == 'x')
System.out.println(word[i] + "es");
else if (word[i].charAt(len-1) == 'h' && len > 1) {
if(word[i].charAt(len-2) == 'c' || word[i].charAt(len-2) == 's')
System.out.println(word[i] + "es");
else
System.out.println(word[i] + "s");
}
else
System.out.println(word[i] + "s");
}
}
}
}
Code: Select all
3 20
rice rice
spaghetti spaghetti
octopus octopi
rice
lobster
spaghetti
strawberry
octopus
peach
turkey
boy
buy
bay
grey
biy
too
vex
brash
nexus
chaste
park
label
snake
Code: Select all
rice
lobsters
spaghetti
strawberries
octopi
peaches
turkeys
boys
buys
bays
greys
biys
tooes
vexes
brashes
nexuses
chastes
parks
labels
snakes
Looks likeShiba wrote:i've got AC with the same alogorithm in C++. But in case of Java there is always RE. can anyone plz help me. where is my fault??
Code: Select all
Scanner input
Code: Select all
#include <stdio.h>
#include <string.h>
int isConsonant(char ch)
{
int f = 1;
if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u'){
f = 0;
}
else{
f = 1;
}
return f;
}
int comp(char s1[], char s2[])
{
int f = 0, i, l1 = 0, l2 = 0;
l1 = strlen(s1);
l2 = strlen(s2);
if(l1 == l2){
for(i = 0; i < l1; i++){
if(s1[i] != s2[i]){
f = 0;
break;
}
else{
f = 1;
}
}
}
return f;
}
int main()
{
int l, n, i, j, k, len, m, f, p, f1, l1;
char irr[105][205], tmp1[105], tmp2[105], instr[105];
scanf("%d %d", &l, &n);
getchar();
for(i = 0; i < l; i++){
gets(irr[i]);
}
for(i = 0; i < n; i++){
gets(instr);
f1 = 1;
for(j = 0; j < l; j++){
len = 0;
for(p = 0; irr[j][p] != '\0'; p++){
len++;
}
m = 0;
f = 0;
f1 = 1;
for(k = 0; k <= len; k++){
if(irr[j][k] != ' ' && f == 0){
tmp1[m++] = irr[j][k];
}
else if(irr[j][k] != '\0' && f == 1){
tmp2[m++] = irr[j][k];
}
else if(irr[j][k] == ' '){
tmp1[m++] = '\0';
m = 0;
f = 1;
}
else if(irr[j][k] == '\0'){
tmp2[m] = '\0';
f = 0;
}
}
if(comp(tmp1, instr) == 1){
printf("%s\n", tmp2);
f1 = 0;
break;
}
}
if(f1 == 1){
l1 = strlen(instr);
if((isConsonant(instr[l1-2]) == 1) && (instr[l1-1] == 'y')){
for(i = 0; i < l1-1; i++){
printf("%c", instr[i]);
}
printf("ies\n");
}
else if(instr[l1-1] == 'o' || instr[l1-1] == 's' || instr[l1-1] == 'x'){
printf("%s", instr);
printf("es\n");
}
else if((instr[l1-2] == 'c' || instr[l1-2] == 's') && instr[l1-1] == 'h'){
printf("%s", instr);
printf("es\n");
}
else{
printf("%s", instr);
printf("s\n");
}
}
}
return 0;
}
Code: Select all
scanf("%d %d", &l, &n);
char singular[30][30], plural[30][30];
for(i = 0; i < l; i++) {
while (getchar() != '\n');
scanf(" %s %s", singular[i], plural[i]);
}