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

How do I print \n in C or C++ programming?
void main () { printf(" "); getch(); }
Supriyo
0 0
6
What is the best website to learn c language?
In case of problems you will face while making programs, you may take help of google. There may be the situation when you need a helping hand to make clear the basic concepts of programming and internal...
Nom
Is it necessary to learn data structures in C language only?
data structure helpful to improve your coding stability
Vikas
0 0
8
Is C programming the best for beginners?
Yes, it is good to start with C so that other programming would be easy to understand
Amit
0 0
7
How do I execute the Java program?
if using command prompt - run that command java program file name ( make sure java class name and file name should be same) if using text-pad press ctrl+1 if using netbeans press run button etc.
Sharmistha
0 0
6

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

Ask a Question

Related Lessons

Some interview questions for freshers on C language
Q1. What are the two forms of #include? There are two variants of #include. The one is #include and the other one is #include”file”. In general the first form that is #include is used to...

Difference Between C Language and C Program
C Language: C Language is structured, high level and machine independent language. C Program: C Program is the collection of functions that are supported by C library.
S

Shashwat Kumar

0 0
0

Internet of Things, Social Media Becoming Part of E-Discovery Landscape
The days when e-discovery consisted of handing over copies of e-mails to address Freedom of Information Act (FOIA) requests, compliance regulations or other legal obligations are over. Now, it's just as...

Bit wise operators in C
Bit Wise Operators Bit Wise operators are manipulates of individual bits with in a word of memory. The bit wise operators can be divided in to three general category. One’s Complement...

Introduction to Programming Languages
What is a Programming Language? A programming language is a formal computer language or constructed language designed to communicate instructions to a machine, particularly a computer. Programming languages...

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