UVA Solution 417 - Word Index in C++11- Volume 4 - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Tuesday, May 9, 2017

UVA Solution 417 - Word Index in C++11- Volume 4

UVA Solution 417 - Word Index - Volume 4


UVA Online Judge Solution 417 - Word Index | Volume 4
UVA Problem Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=358

Problem Name: 417 - Word Index
Problem Number : UVA - 417 - Word Index
Online Judge : UVA Online Judge Solution
Volume: 4
Solution Language : C, C plus plus, C++11

UVA Solution 417 - Word Index - Volume 4

UVA Solution 417 - Word Index Code in C, CPP:


#include <stdio.h>
#include <string.h>

int main() {
 int i, j;
 int C[50][50] = {};
 C[0][0] = 1;
 for(i = 1; i < 50; i++) {
  C[i][0] = 1;
  for(j = 1; j <= i; j++)
   C[i][j] = C[i-1][j-1] + C[i-1][j];
 }
 char s[10];
 while(scanf("%s", &s) == 1) {
  int len = strlen(s), idx = 0;
  for(i = 1; i < len; i++) {
   if(s[i] < s[i-1]) {
    puts("0");break;
   }
   idx += C[26][i];
  }
  if(i != len) continue;
  for(i = 0; i < len; i++) {
   for(j = (i == 0) ? 1 : s[i-1]-'a'+2; j <= s[i]-'a'; j++)
    idx += C[26-j][len-i-1];
  }
  printf("%d\n", idx+1);
 }
    return 0;
}

No comments:

Post a Comment