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 use of getch(); in the end of c program
getch() is used to hold the console(output) window on the screen after the whole program run is completed till the user enters a key from keyboard. However, the character entered is not displayed on screen....
Priyanka
What is meant by high-order and low-order bytes?
Lower order and higher-order bytes are the terms used while computing calculations in a programming language. Usually, numbers are written from left to right. The left is the most significant bit, and...
Vishal
0 0
9
Which are the best books to learn C?
- Yashwant Kanetkar - E Balagurusamy
Kratika
What are important topics in C language?
Important topics in the C programming language include: 1. Variables and data types 2. Control flow (loops and conditional statements) 3. Functions and recursion 4. Arrays and strings 5. Pointers...
Everest
0 0
5

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 a Programming Language
What is a Language? Language is a communication system of human. What is a programming Language? A programming Language is a formal constructed language design to communicate...

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

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

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

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 >

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 >

Information technology consultancy or Information technology consulting is a specialized field in which one can set their focus on providing advisory services to business firms on finding ways to use innovations in information technology to further their business and meet the objectives of the business. Not only does...

Read full article >

Whether it was the Internet Era of 90s or the Big Data Era of today, Information Technology (IT) has given birth to several lucrative career options for many. Though there will not be a “significant" increase in demand for IT professionals in 2014 as compared to 2013, a “steady” demand for IT professionals is rest assured...

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