Posts

prasad

  #include< iostream > using namespace std; int main() { } int OddEvenFine( int date, int cars[], int n) { if (date% 2 == 0 ) { int sum= 0 ; for ( int i= 0 ;i<n;i++) { if (cars[i]% 2 != 0 ) { sum=sum+ 250 ; } } return sum; } else { int sum2= 0 ; for ( int i= 0 ;i<n;i++) { if (cars[i]% 2 == 0 ) { sum2=sum2+ 250 ; } } return sum2; } }

fayaz

  #include < iostream > using namespace std; int main() { int n;cin>>n; int arr[n]; for ( int i= 0 ;i<n;i++) { cin>>arr[i]; } int flagfornegative= 0 ; int maxcount= 0 ; int currentcount= 0 ; for ( int i= 0 ;i<n;i++) { if (arr[i]< 0 ) { currentcount+= 1 ; flagfornegative= 1 ; } else { flagfornegative= 0 ; currentcount= 0 ; } if (maxcount<currentcount) { maxcount=currentcount; } } if (maxcount== 1 ) { int maxx=arr[ 0 ]; for ( int i= 1 ;i<n;i++) { if (arr[i]< 0 ) { if (arr[i]<maxx) { maxx=arr[i]; } } } long sum= 0 ; for ( int i= 0 ;i<n;i++) { if (arr[i]!=maxx) { sum+=arr[i]; } else { sum=sum+=-maxx; } } cout<<sum; } }

rahul question

  #include < iostream > using namespace std; int main() { double inputweight;cin>>inputweight; int countryid;cin>>countryid; if (countryid== 101 ) { if (inputweight>= 58 && inputweight<= 65 ) { cout<< 0 << " " << "chicago" ; } else if (inputweight< 58 ) { cout<< 58 -inputweight<< " " << "chicago" ; } else { cout<<inputweight- 65 << " " << "chicago" ; } } else if (countryid== 102 ) { if (inputweight>= 66 && inputweight<= 72 ) { cout<< 0 << " " << "Vancouver" ; } else if (inputweight< 66 ) { cout<< 66 -inputweight<< " " << "Vancouver" ; } else { cout<<inputweight- 72 << " " << "Vancouver" ; } } else if (countryid== 103 ) { if (inputweight...

Tcs assessment problem: museum problem.

 package tcs_assessments; import java.util.Scanner; public class museumwalaprogram { //below is the main method         public static void main(String[] args) {                  Scanner sc=new Scanner(System.in);         Museum[] museum=new Museum[5];         for (int i = 0; i <museum.length ; i++) {             int mi=sc.nextInt();             sc.nextLine();             String mn=sc.nextLine();             String ml=sc.nextLine();             int e=sc.nextInt();             sc.nextLine();             double r=sc.nextDouble();             sc.nextLine();             boolean rc=sc.nextBoolean();   ...

TCS JAVA PROGRAMMING QUESTION.(problem of appliances)

  package youtube ; import java.util.Scanner ; public class MyClass { // below is the main method public static void main ( String [] args ) { // below is the code for creating the array of the Appliance class Appliance [] appliance = new Appliance[ 4 ] ; // below is the code for creating the scanner object and taking input Scanner sc = new Scanner( System . in ) ; for ( int i = 0 ; i < appliance . length ; i ++) { int applianceid = sc .nextInt() ; sc .nextLine() ; String appliancename = sc .nextLine() ; String appliancecategory = sc .nextLine() ; double applianceamount = sc .nextDouble() ; appliance [ i ]= new Appliance( applianceid , appliancename , appliancecategory , applianceamount ) ; } sc .nextLine() ; int applianceid = sc .nextInt() ; boolean insurance = sc .nextBoolean() ; sc .nextLine() ; String appliancecategory = sc .nextL...

convert the integer number to its binary representation.

  Binary representation School Accuracy: 36.68% Write a program to print Binary representation of a given number N. Example 1: Input: N = 2 Output: 000000000000000000000000000010 Explanation: The binary representation of 2 is '10' but we need to print in 30 bits so append remaining 0's in the left.     ANSWER: string getBinaryRep(int N) { vector<int> vec; while(N>0) { int rem=N%2; vec.push_back(rem); N=N/2; } int l=30-vec.size(); for(int i...

Problem no 18(array):count the number of pairs in array whose sum is equal to the given number.

  Count pairs with given sum Easy Given an array of N integers, and an integer  K , find the number of pairs of elements in the array whose sum is equal to K . Example 1: Input: N = 4, K = 6 arr[] = {1, 5, 7, 1} Output: 2 Explanation: arr[0] + arr[1] = 1 + 5 = 6 and arr[1] + arr[3] = 5 + 1 = 6.     ANSWER:  int getPairsCount(int arr[], int n, int k) {         int c=0;         unordered_map<int,int> m;         for(int i=0;i<n;i++)   ...