Posts

Showing posts from January 22, 2018

Zoho Second round question - X Form String

Print the word with odd letters as P M R A O R G O R R A P M      Print in X form  C++ Program: #include<iostream> #include<conio.h> #include<string.h> using namespace std; int main() { string s; cin >> s; int n = s.length(); for(int i = 0; i<=(n-1)/2;i++) { if(i!=n-1-i) { for(int j=0;j<i;j++) {cout<<" ";} cout<<s[i]; for(int j=i+1;j<n-i;j++) {cout<<" ";} cout<<s[n-1-i]; cout<<"\n"; } else { for(int j=0;j<i;j++) {cout<<" ";} cout<<s[i]<<"\n"; } } int k =(n-1)/2; int m = (n-1)/2; int l=(n-1)/2; for(int i = 0; i<=(n-1)/2;i++) { m=m-1; l=l+1; for(int j=0;j<m;j++) { cout<<" "; } cout<<s[m];

Zoho - Second round- Reversing the vowels

Given a string, reverse only the vowels present in it and print the resulting string. Input : First line of the input file contains an integer T denoting the number of test cases. Then T test cases follow. Each test case has a single line containing a string. Output : Corresponding to each test case, output the string with vowels reversed. Example: Input: practice Output: prectica C++ Program: #include<iostream> #include<conio.h> #include<string.h> using namespace std; int main() {     string a,b;     cin >> a;     int len= a.length();     int count=0;     for(int i=0;i<len;i++)     {     if(a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u')     {     b=b+a[i];     count+=1;     }     }     for(int i=0;i<len;i++)     {     if(a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u')     {     count -=1;     a[i]=b[count];         }     }     cout <&

Zoho interview question Question and Answer

Given an array of integers, rearrange the array in such a way that the first element is first maximum and second element is first minimum. Example —> Input: {1, 2, 3, 4, 5, 6, 7} | Output : {7, 1, 6, 2, 5, 3, 4} C++ Program  #include <iostream> #include<conio.h> using namespace std; int main() { int a[100],n=0,temp,max,min; cin >> n; for(int i=0;i<n;i++) { cin>>a[i]; } cout<<"\n"; for(int i=0 ;i<n;i++) { for( int j=i+1;j<n;j++) { if(a[i]<a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } } max=0; min=n-1; for(int i=1 ;i<=n;i++) { if(i%2==0) { cout<<a[min--]; } else { cout<<a[max++]; } } getch(); return 0; }   Happy Coding!!