Cod sursa(job #2152)

Utilizator AlxCojocaru Alexandru Alx Data 16 decembrie 2006 08:53:46
Problema 12-Perm Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include<stdio.h>
#include<string.h>
char st[1024];
char s[128],v[256];
int nr,k;
void cit()
{
    freopen("bilete.in","r",stdin);
    scanf("%s",s);
}
void rez()
{
    int lg,i;
    lg=strlen(s);
    for(i=0;i<lg;i++)
        if(v[s[i]]==0)
        {
            st[++k]=s[i];
            v[s[i]]=1;
        }
        else if(v[s[i]]==1&&s[i]!=st[k])
        {
            while(st[k]!=s[i])
            {
                v[st[k]]=0;
                k--;
                nr++;
            }
        }
       nr+=k;
}
void scr()
{
    freopen("bilete.out","w",stdout);
    printf("%d\n",nr);
}
int main()
{
    cit();
    rez();
    scr();
    return 0;
}