Sorry for disturbing you .
I was trying to solve this SPOJ problem , but failed .
Any suggestion ? Hint ? Tutorial ? Or solution ?
Waiting for positive reply .
My main code
Thanks in advance .
# | User | Rating |
---|---|---|
1 | ecnerwala | 3648 |
2 | Benq | 3580 |
3 | orzdevinwang | 3570 |
4 | cnnfls_csy | 3569 |
5 | Geothermal | 3568 |
6 | tourist | 3565 |
7 | maroonrk | 3530 |
8 | Radewoosh | 3520 |
9 | Um_nik | 3481 |
10 | jiangly | 3467 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 174 |
2 | awoo | 164 |
2 | adamant | 164 |
4 | TheScrasse | 159 |
4 | nor | 159 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 150 |
8 | SecondThread | 147 |
9 | orz | 146 |
10 | pajenegod | 145 |
Help needed in a SPOJ problem .
Sorry for disturbing you .
I was trying to solve this SPOJ problem , but failed .
Any suggestion ? Hint ? Tutorial ? Or solution ?
Waiting for positive reply .
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
string s;
cin >> s;
map <char,set<int>>mp;
int tot = s.size();
vector<bool>a(10, 0);
for(int i=0;i<tot;i++)
{
char x = s[i];
mp[x].insert(i);
a[x -'0'] = 1;
}
for(int i=0;i<10;i++)
{
if(a[i]==0)
{
printf("%d",i);
return 0;
}
}
for(int i=10;;i++)
{
string c = to_string(i);
int len = c.size();
char st = c[0];
bool ok = 1;
for(auto it : mp[st])
{
int start = it;
if(start + len > tot) continue;
string cur = s.substr(start,len);
if(cur == c) ok = 0;
}
if(ok==1)
{
printf("%d",i);
return 0;
}
}
}
Thanks in advance .
Name |
---|