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 the benefit of using enum to declare a constant?
ENUMS.. Can give numerical values for Sunday, Monday,... Easy to use in coding... Makes the program more readable/ understandable, than using 1,2,3.. Etc.
Sita
0 0
7
What is a stream?
Stream means flow... ofstream This data type represents the output file stream and is used to create files and to write information to files. ifstream This data type represents the input file stream and is used to read information from files
Nilam
What is the concatenation operator?
In many programming languages, string concatenation is a binary infix operator. The + (plus) operator is often overloaded to denote concatenation for string arguments: "Hello, " + "World" has the value...
R.s.praveen
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

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

Ask a Question

Related Lessons

Advantages of C++ Language
Advantages of C++ - C++ is a profoundly convenient dialect and is frequently the dialect of decision for multi-gadget, multi-stage application advancement. - C++ is a protest situated programming dialect...

Basic Concepts of Web Designing
An introduction to domain names, web servers, and website hosting 1)What is the web? In a nutshell, the web is a whole bunch of interconnected computers talking to one another. The computers (on the...

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...
S

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...

C Program-Error Handling
//Header files #include<stdio.h>#include<conio.h>#include<stdlib.h> //Main function void main(){ int dividend=10; int divisor=0; int quotient; //Function for clearing screen clrscr(); ...
S

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