UrbanPro

Learn C Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

How do I write a program in C to find the rank of a word (with repetition)?

Asked by Last Modified  

Follow 1
Answer

Please enter your answer

Computer Intelligent

#include long fact(int n) { long f=1; while (n > 0) { f *= n; n--; } return f; } int find_rank(char s, int len) { long rank=1; int i, j, k, l, fr, f; //fr is frequency char sorted, cur, t, pre; for (i = 0; i=0 && sorted > t; --k) sorted = sorted; sorted = t; ...
read more
#include long fact(int n) { long f=1; while (n > 0) { f *= n; n--; } return f; } int find_rank(char s[], int len) { long rank = 1; int i, j, k, l, fr[26], f; //fr is frequency char sorted[100], cur, t, pre; for (i = 0; i < len -1 ; ++i) { cur = s[i]; strcpy(sorted, s + i); l = len - i; memset(fr, 0, sizeof(fr)); fr[sorted[0] - 'a']++; for (j = 1; j < l; ++j) { t=sorted[j]; fr[t-'a']++; for (k = j-1; k>=0 && sorted[k] > t; --k) sorted[k+1] = sorted[k]; sorted[k+1] = t; } pre = 1; for (k = 0; sorted[k] != cur ;++k) { if (sorted[k] == pre) continue; pre = sorted[k]; f = fact(l - 1); fr[pre - 'a']--; for (j = 0; j < 26; ++j) if (fr[j]) f /= fact(fr[j]); rank += f; fr[pre - 'a']++; } } return rank; } int main() { char s[100]; scanf("%s", s); printf("%d", find_rank(s, strlen(s))); return 0; } read less
Comments

Advance Excel And VBA Training

lets see how to find the rank of word if the letter in a word having repetition. Before preceding to the tutorial some of the basics we should know. Like how many total words can be formed using letters of INDIA. In letter “INDIA” there are 2 I and no other letter is repeating. So the no. of words...
read more
lets see how to find the rank of word if the letter in a word having repetition. Before preceding to the tutorial some of the basics we should know. Like how many total words can be formed using letters of INDIA. In letter “INDIA” there are 2 I and no other letter is repeating. So the no. of words that can form using letter of INDIA will be 5! / 2! = 60. Now we may proceed to the next point. Algorithm 1. Take that word which we have to find the rank. Now the letter of that word is repeating. I take “BOMBAY” 2. Now arrange the letter of “BOMBAY” in alphabetical order. Now they are “ABBMOY“. 3. Pickup first letter from “ABBMOY” that’s “A“. Now compare “A” from “BOMBAY”. Does the letter “A” in the first we want? NO. Now how many words can be made if we extract “A” from “ABBMOY“. A = 5! / 2! = 60 Now proceed to the next. 4. Pickup second letter from “ABBMOY” that’s “B“. Now compare “B” from “BOMBAY“. Does the letter “B” in the first we want? Yes. Now fix the letter “B“. [B] Then go to once again on the first letter of “ABBMOY”. Does “A” we want? NO. Then write down how many words can be made with starting [B]A [B]A = 4! = 24 5. Repeat the process until we get the letter which we want after B in the word “BOMBAY“. [B]B = 4! = 24 [B]M = 4! = 24 [B]O. “O” we want. So fix this and get back to the starting. 6. Does we want now [BO]A? NO. So write down once again. [BO]A = 3! = 6 [BO]B = 3! = 6 [BO]M. “M” we want now. So fix this too. And get back to the starting. 7. Does we want [BOM]A? No. So write down once again. [BOM]A = 2! = 2 [BOM]B. “B” we want. So fix this too. And get back to starting. We see “A” also we want now. So fix this too. And the last letter is “Y” We also want this. So we reach to the end. Now we can write. [BOMBAY] = 1. 8. Now add the entire sum which we earn. That’s 60 + 24 +24 + 24 + 6 + 6 + 2 + 1 = 147. That’s the answer. Now for Word “INDIA” 1. [ADIIN] 2. A = 4! / 2! = 12 2. D = 4! / 2! = 12 3. [I]A = 3! = 6 4. [I]D = 3! = 6 5. [I]I = 3! = 6 6. [IN]A = 2! =2 7. [IND]IA = 1. Now add all. 12 + 12 + 6 + 6 + 6 + 2 + 1 = 45. So that’s the answer. Congratulation now you are able to find RANK of any word if its letters having repetition or not. In the case of repetition there is no shortcut. read less
Comments

Related Questions

What is important topics in C-language for interviews???
Functions, Arrays , String, pointers , structures
Gayu
How do I start learning C programming and finish it in one month?
Please follow the book "C Programming" by Detal & Detal. Its an applied book easy to understand compare to others. U may also learn through online free tutorial.
Pallavi
0 0
8
How and where do I start learning C programming?
C language is the basic of the programming to learn the basic of programming we learn the c language
Gaurav
0 0
7
Can an ECE graduate with some knowledge of C language learn SQL?
Yes ECE graduate student learn SQL languuage bcuz SQL is. A structured query language. it all query depends upon the logic. In which table is used Nd database is maitained
Anand
0 0
5
Are C Programmers currently in demand?
Ofcourse, C is alwasy in demand. In the beginning a lot of the big project developed in C language. Now a days, there are a lot of language in market and speciallity is growing in IT field. For a big organization...
Harsha

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

What is Safety-Critical Software?
A software whose failure may cause death or injuries to the users called Safety-Critical Software.The software present as part of Aeroplanes, or present in Rail as railway signalling software or Automotive...

C Program-Temperature [conversion from farenheit to degree celsius]
//WAP to convert temperture from farenheit into degree celsius //Header files#include<stdio.h>#include<conio.h> //Main functrion void main(){ //Variable declaration of type float float...

Working with C/C++ applications
Inorder to learn C and C++ programming languages one can work with various editors available.To name a few are the most popular one is turbo c++, DEV C++, Eclipse, NetBeans. Here are the screen shots...

C Program-Vowels and Consonants
/*WAP to print the character entered by user is a vowel or consonant*/ //Header files #include<stdio.h>#include<conio.h> //Main functionvoid main(){ char c; //Function for clearing screen...

How to write shared library program using C Programming?
Library Name : hellofilename : hello.c#include void Hello(){ printf("Hello World .. How are you 1\n");}======================================Header File:hello.h#ifndef __HELLO_H#define __HELLO_Hvoid Hello(void);#endif===============================Application...

Recommended Articles

Lasya Infotech is a Hyderabad based IT training institute founded in 2016 by O Venkat. Believing in his innovation, passion and persistence and with a diverse blend of experience, he started his brainchild to deliver exemplary professional courses to aspiring candidates by honing their skills. Ever since the institute envisions...

Read full article >

Brilliant Academy is one of the reputed institutes for B.Tech tuition classes. This institute is specialised in delivering quality tuition classes for B.E, Engineering - all streams and Engineering diploma courses. Incorporated in 2012, Brillant Academy is a brainchild of Mr Jagadeesh. The main motto of the academy is to...

Read full article >

Business Process outsourcing (BPO) services can be considered as a kind of outsourcing which involves subletting of specific functions associated with any business to a third party service provider. BPO is usually administered as a cost-saving procedure for functions which an organization needs but does not rely upon to...

Read full article >

Microsoft Excel is an electronic spreadsheet tool which is commonly used for financial and statistical data processing. It has been developed by Microsoft and forms a major component of the widely used Microsoft Office. From individual users to the top IT companies, Excel is used worldwide. Excel is one of the most important...

Read full article >

Looking for C Language Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for C Language Classes?

The best tutors for C Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C Language with the Best Tutors

The best Tutors for C Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more