Friday 16 September 2016

Solution of URI 2242 :: Huaauhahhuahau


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>

int main()
{
    int i, j=0, lnth;
    char x[60], y[60];
    scanf("%s", x);
    for(i=0; x[i]; i++)
    {
        if(x[i]=='a' || x[i]=='e' || x[i]=='i' || x[i]=='o' || x[i]=='u')
        {
            y[j] = x[i];
            j++;
        }
    }
    y[j] = '\0';
    lnth = strlen(y);
    for(i=0, j=lnth-1; i < lnth; i++, j--)
    {
        if(y[i] != y[j])
        {
            printf("N\n");
            return 0;
        }
    }
    printf("S\n");
    return 0;
}

3 comments:

  1. Hello . Do you know how to solve by Java?

    ReplyDelete
    Replies
    1. im not an expert but i do it:

      String in = ler.nextLine();
      char A[] = in.toCharArray();
      char Y[] = new char[A.length];
      char X[] = new char[A.length];
      int j = Y.length - 1;

      for (int i = 0; i < A.length; i++) {
      if (A[i] == 'a' || A[i] == 'e' || A[i] == 'i' || A[i] == 'o' || A[i] == 'u') {
      Y[j] = A[i];
      j--;
      }
      }
      j = 0;
      for (int i = 0; i < A.length; i++) {
      if (A[i] == 'a' || A[i] == 'e' || A[i] == 'i' || A[i] == 'o' || A[i] == 'u') {
      X[j] = A[i];
      j++;
      }
      }
      String y = new String(Y);
      String x = new String(X);
      x = x.trim();
      y = y.trim();

      if (x.equals(y)) {
      System.out.println("S");
      } else {
      System.out.println("N");
      }

      Delete

Note: only a member of this blog may post a comment.