Computer Science, asked by swethaganta, 1 year ago

The objective is to form the maximum possible time in the HH:MM:SS format using any six of nine given single digits (not necessarily distinct)

Given a set of nine single (not necessarily distinct) digits, say 0, 0, 1, 3, 4, 6, 7, 8, 9, it is possible to form many distinct times in a 12 hour time format HH:MM:SS, such as 10:36:40 or 01:39:46 by using each of the digits only once. The objective is to find the maximum possible valid time (00:00:01 to 12:00:00) that can be formed using some six of the nine digits exactly once. In this case, it is 10:49:38.

Answers

Answered by lakshmansai999othc0k
10
#include <bits/stdc++.h>using namespace std;
// strings at index 0 is not used, it is to make array// indexing simplestring one[] = { "", "one ", "two ", "three ", "four ",                 "five ", "six ", "seven ", "eight ",                 "nine ", "ten ", "eleven ", "twelve ",                 "thirteen ", "fourteen ", "fifteen ",                 "sixteen ", "seventeen ", "eighteen ",                 "nineteen "               };
// strings at index 0 and 1 are not used, they is to// make array indexing simplestring ten[] = { "", "", "twenty ", "thirty ", "forty ",                 "fifty ", "sixty ", "seventy ", "eighty ",                 "ninety "               };
// n is 1- or 2-digit numberstring numToWords(int n, string s){    string str = "";    // if n is more than 19, divide it    if (n > 19)        str += ten[n / 10] + one[n % 10];    else        str += one[n];
    // if n is non-zero    if (n)        str += s;
    return str;}
// Function to print a given number in wordsstring convertToWords(long n){    // stores word representation of given number n    string out;
    // handles digits at ten millions and hundred    // millions places (if any)    out += numToWords((n / 10000000), "crore ");
    // handles digits at hundred thousands and one    // millions places (if any)    out += numToWords(((n / 100000) % 100), "lakh ");
    // handles digits at thousands and tens thousands    // places (if any)    out += numToWords(((n / 1000) % 100), "thousand ");
    // handles digit at hundreds places (if any)    out += numToWords(((n / 100) % 10), "hundred ");
    if (n > 100 && n % 100)        out += "and ";
    // handles digits at ones and tens places (if any)    out += numToWords((n % 100), "");
    return out;}
// Driver code
int calculateSpaces(string str){
int count=0; for(unsigned int i=0;i<str.size();i++){
if(str[i]==' ') count++;

} return count;


}
int checkPrime(int num){
if(num%2==0) return false; for(int i=3;i<=sqrt(num);i+=2) if(num%i==0)  return false;
return true;


}int main(){ int m,n,prcount;

     cin>>m;     cin>>n;     prcount=0;     for(int i=m;i<=n;i++)      {      if(checkPrime(i))      {
   string numstr=convertToWords(i);    int len=numstr.length();   // cout<<numstr<<numstr.length()<<" spaces "<<calculateSpaces(numstr)<<endl;    int spaces=calculateSpaces(numstr);    //cout<<len-spaces<<endl;    if(checkPrime(len-spaces))     prcount++;   // cout<<;
}
}cout<<prcount<<endl;    return 0;}

mahidhoni1877: thank you....
mahidhoni1877: if you know any other answers from that??
lakshmansai999othc0k: yaaa
lakshmansai999othc0k: yes
mahidhoni1877: pls share if u have....
lakshmansai999othc0k: haaa okk
lakshmansai999othc0k: may i know which college
mahidhoni1877: ies thrissur and u??
lakshmansai999othc0k: anits
saitejavadala1othhhh: how it can be executed
Answered by subodh1903
0
class Main2{  public static void main(String[] arg) throws Exception{ java.util.Scanner scanner = new java.util.Scanner(System.in);  int n = scanner.nextInt();  char c;  int[][] arr = new int[n+1][5];  for(int i = 0; i < n+1; i++){     String line = scanner.nextLine(); //System.out.println(line); if(!line.equals("")) {     String[] line1 = line.split(",");// System.out.println(line1);     for(int j = 0 ; j < line1.length; j++){ //System.out.println(line1[j]);      arr[i-1][j] = Integer.parseInt(line1[j]); }}  }      for(int i = 0; i < n+1; i++){ for(int j = 0; j < 5; j++){ for(int k = 0; k < 5; k++){ if(arr[i][j] <arr[i][k]){ int temp = arr[i][j]; arr[i][j] = arr[i][k]; arr[i][k] = temp; } } }  }    /*for(int i = 0; i < n+1; i++){ for(int j = 0; j < 5; j++){ System.out.println(arr[i][j]); } }*/      int[] sum = new int[n+1];  sum[0] = arr[n][4];  int max = arr[n][4];int p = 1;
for(int i=n-1;i>=0;i--){ for(int j =4;j>=0;j--) { if(arr[i][j]<max) { max =arr[i][j]; sum[p]=arr[i][j]; //System.out.println(max); break; } } if(sum[p]==0) { sum[p-1]=arr[i][4]; max = sum[p-1]; } p++;}  /*for(int i =0 ;i<n;i++){ for(int j =0;j<5;j++) { System.out.println(arr[i][j]); }

}*///System.out.println();int val=0;for(int i=0;i<n+1;i++){//System.out.println(sum[i]); val = val+sum[i];}//System.out.println(); System.out.print(val);}//the code is written by subodh latkar 
}








Similar questions