/**************************************
Implement an algorithm to determine if a string has all unique characters What if you
can not use additional data structures?
Note: this file cannot be built nor executed. But under Linux the same file can work!
Copyright: Ben
Mod time: 4.17,2012
***************************************/
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int Bitmap[128];
char ch;
bool unique = true;
//initialize the bitmap to 0.
for(int i = 0; i < 128; i++)
{
Bitmap[i] = 0;
}
freopen("string.txt", "r", stdin);
//keep reading until the end of file.
while((ch = fgetc(stdin)) != EOF)
{
Bitmap[ch - 1]++; //put into the correspondent container.
if(Bitmap[ch - 1] > 1)
{
unique = false;
break;
}
}
//printf((unique) ? ("Unique String!!\n") : ("Not a unique string\n"));
if(unique)
{
printf("Unique String!!\n");
}
else
{
printf("Not a unique string\n");
}
fclose(stdin);
return 0;
}
Implement an algorithm to determine if a string has all unique characters What if you
can not use additional data structures?
Note: this file cannot be built nor executed. But under Linux the same file can work!
Copyright: Ben
Mod time: 4.17,2012
***************************************/
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int Bitmap[128];
char ch;
bool unique = true;
//initialize the bitmap to 0.
for(int i = 0; i < 128; i++)
{
Bitmap[i] = 0;
}
freopen("string.txt", "r", stdin);
//keep reading until the end of file.
while((ch = fgetc(stdin)) != EOF)
{
Bitmap[ch - 1]++; //put into the correspondent container.
if(Bitmap[ch - 1] > 1)
{
unique = false;
break;
}
}
//printf((unique) ? ("Unique String!!\n") : ("Not a unique string\n"));
if(unique)
{
printf("Unique String!!\n");
}
else
{
printf("Not a unique string\n");
}
fclose(stdin);
return 0;
}