Problem: Given a string, Remove all the duplicate chars, string may include spaces.
Solution Hints:solN; ASCII char valaus range from -128 to 127.
The following solution did not get AC from OJ. My guess is, there may be a problem with that OJ.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
#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; } |