ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories >> Code-Snippets >> Programming-Code >> C-Code
 
 
 
Question
Write a prog to accept a given string in any order and flash
error if any of the character is different. 

For example : If abc is the input then abc, bca, cba, cab
bac are acceptable, but aac or bcd are unacceptable.
 Question Submitted By :: Coder_1
I also faced this Question!!     Rank Answer Posted By  
 
Answer
both of the solutions above given have complexity O(N^2),
i have tried to solve it in O(N).let me inform if there is 
any bug or better solution .

#include<iostream>
using namespace std;
int main()
{
    int a[130],a1[130];
    memset(a,0,sizeof(a));
    memset(a1,0,sizeof(a));
    char ans[1000];
    char str[]="putanystringhere";
    for(int i=0;i<sizeof(str)/sizeof(char)-1;i++)
    {
        a[(int)str[i]]+=1; 
    }
    cout<<"Enter any string of length
"<<sizeof(str)/sizeof(char)-1<<" :";
    cin>> ans;  
    for(int i=0;i<sizeof(str)/sizeof(char)-1;i++)
    {
        a1[(int)ans[i]]+=1; 
    }
    bool flag=true;
    for(int i=0;i<sizeof(str)/sizeof(char)-1;i++)
    {
           if(a[(int)str[i]]!=a1[(int)str[i]])
            {
                     flag=false;
                     break;
            }
    }
    if(flag==true)
    cout<<"No error";
    else
    cout<<"Error";
    system("pause");
    return 0;
}
 
0
Rahul Shandilya
 
View All Answers
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com