Removing duplicate chars[Microsoft]

Problem: Given a string, Remove all the duplicate chars, string may include spaces.

Solution Hints:solN; ASCII char valaus range from -128 to 127.

Link

The following solution did not get AC from OJ. My guess is, there may be a problem with that OJ.

#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

int main() {
	//code
	int t;
	int arr[1005];
	string str;
	scanf("%d",&t);
	//t+=1;
	getchar();
	while(t--)
	{
	    getline(cin,str);
	    for(int i=0;i<1005;i++)
	        arr[i]=0;
	    for(int i=0;i<str.size();i++)
	    {
	        if(arr[(str[i]-'0')+128]==0)
	        //printf("%c",str[i]);
	        cout<<str[i];
	        arr[(str[i]-'0')+128]=1;
	    }
	    printf("\n");
	}
	return 0;
}

 

 

Comments are closed.