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.

Answer Posted / rahul shandilya

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;
}

Is This Answer Correct ?    1 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

#include int main(void) { int a=4, b=2; a=b<>2 ; printf("%d",a); return 0; }

1067


why do you use macros? Explain a situation where you had to incorporate macros in your proc report? use a simple instream data example with code ?

2258


Write a routine to implement the polymarker function

4375


Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?

3845


How to palindrom string in c language?

8836






why nlogn is the lower limit of any sort algorithm?

2373


Design an implement of the inputs functions for event mode

2957


What is full form of PEPSI

1865


Develop a routine to reflect an object about an arbitrarily selected plane

2994


write a c program to input initial & final time in the format hh:mm and find the time intervel between them? Ex inputs are initial 06:30 final 00:05 and 23:22 final 22.30

2219


can you use proc sql to manpulate a data set or would u prefer to use proc report ? if so why ? make up an example and explain in detail

2325


Write a Program in 'C' To Insert a Unique Number Only. (Hint: Just Like a Primary Key Numbers In Database.) Please Some One Suggest Me a Better Solution for This question ??

1770


could you please send the program code for multiplying sparse matrix in c????

3067


create a C-code that will display the total fare of a passenger of a taxi if the driver press enter,the timer will stop. Every 10 counts is 2 pesos. Initial value is 25.00

6306


Write a program to model an exploding firecracker in the xy plane using a particle system

3686