Password

QUESTION

Danny has a possible list of passwords of Manny’s facebook account. All passwords length is odd. But Danny knows that Manny is a big fan of palindromes. So, his password and reverse of his password both should be in the list.\n\nYou have to print the length of Manny’s password and it’s middle character.\n\nNote : The solution will be unique.\n\nINPUT \nThe first line of input contains the integer N, the number of possible passwords. \nEach of the following N lines contains a single word, its length being an odd number greater than 2 and lesser than 14. All characters are lowercase letters of the English alphabet.\n\nOUTPUT \nThe first and only line of output must contain the length of the correct password and its central letter.\n\nCONSTRAINTS \n 1N100.

ANSWER

#include <cstdio>
#include <cstring>
const int maxn = 100;
const int maxk = 16;
int N;
char lista[maxn][maxk];
char tmp[maxk];
void load() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i)
    scanf("%s", (char*) lista[i]);
}
bool ispravna(char *str) {
  int k = strlen(str);
  for (int j = 0; j < k; ++j)
    tmp[k - j - 1] = str[j];
  tmp[k] = 0;
  for (int i = 0; i < N; ++i)
    if (!strcmp(lista[i], tmp))
      return 1;
  return 0;
}
int main() {
  load();
  for (int i = 0; i < N; ++i) {
    if (ispravna(lista[i])) {
      int k = strlen(lista[i]);
      printf("%d %c\n", k, lista[i][k/2]);
      return 0;
    }
  }
  return 1;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.