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  

2 Answers

Learn C Language

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

Can one new to programming learn Java, C, or other languages first?
First you can learn C language because it is Mother of all the all advanced language. then we can learn c++,Java,.NET, because all advanced language syntax is inherits from C language. If u r basic is good then u can learn every advanced language.
Agastya
0 0
5
How do I become good in competitive programming in a year if I have just started learning C language?
The best topics to learn would be Data structures and also the analysis of algorithms..(THESE ARE BASICS BUT IF U LEARN THEM PROPERLY!!! CODING WOULD BE A PIECE OF CAKE FOR U....)
Anmol
0 0
9
What is the difference between #include< > and #include" "
first one is used for predefined header files.. and second is used for user defined header files
Priya
1 0
6
How do you list a file's date and time?
The C date and time operations are defined in the time.h header file time_t current_time; char* c_time_string; /* Obtain current time. */ current_time = time(NULL);
Neelima
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

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