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
#include
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 ?
Write a routine to implement the polymarker function
Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?
How to palindrom string in c language?
why nlogn is the lower limit of any sort algorithm?
Design an implement of the inputs functions for event mode
What is full form of PEPSI
Develop a routine to reflect an object about an arbitrarily selected plane
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
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
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 ??
could you please send the program code for multiplying sparse matrix in c????
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
Write a program to model an exploding firecracker in the xy plane using a particle system