Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("valoare.in");
- ofstream fout("valoare.out");
- int C, N, fr[27];
- char S[1005];
- int top, nr, ok;
- long long st[1005], suma;
- int main()
- {
- fin>>C;
- if(C==1)
- {
- char ch;
- while(fin >> ch)
- {
- if(ch>='A' && ch<='Z')
- fr[ch-'A'+1]++;
- }
- for(int i=1; i<=26; ++i)
- if(fr[i])
- N++;
- fout<<N;
- return 0;
- }
- if(C==2)
- {
- char ch;
- int sum=0, nr=0;
- while(fin>>ch)
- {
- if(isdigit(ch))
- nr=nr*10+(ch-48);
- else
- {
- sum=sum+nr;
- nr=0;
- }
- }
- if(nr)
- sum+=nr;
- fout<<sum;
- return 0;
- }
- fin.get();
- fin.getline(S, 1005);
- if(S[3]=='L')
- {
- for(int i=0; i<(int)strlen(S); i++)
- {
- if(S[i]=='(')
- {
- top++;
- st[top]=-1;
- }
- else if(S[i]>='A' && S[i]<='Z')
- {
- while(S[i]>='A' && S[i]<='Z')
- {
- top++;
- st[top]=(int)(S[i]-'A'+1);
- i++;
- }
- i--;
- }
- else if(S[i]==')')
- {
- if(S[i-1]>='A' && S[i-1]<='Z')
- {
- suma=0;
- while(st[top]!=-1)
- {
- suma+=st[top];
- st[top]=0;
- top--;
- }
- st[top]=suma;
- }
- }
- else if(S[i]>='0' && S[i]<='9')
- {
- if(S[i-2]>='A' && S[i-2]<='Z')
- ok=1;
- int nr=0;
- while(S[i] && (S[i]>='0' && S[i]<='9'))
- nr=nr*10+(S[i]-48), i++;
- i--;
- if(ok)
- st[top]=st[top]*nr;
- else
- {
- int pr=top;
- while(st[pr]!=-1)
- {
- st[pr]=st[pr]*nr;
- pr--;
- }
- }
- }
- ok=0;
- }
- suma=0;
- for(int i=1; st[i]; i++)
- {
- if(st[i]>0)
- suma+=st[i];
- }
- fout<<suma;
- return 0;
- }
- for(int i=0; i<(int)strlen(S); i++)
- {
- if(S[i]=='(')
- {
- top++;
- st[top]=-1;
- }
- else if(S[i]>='A' && S[i]<='Z')
- {
- while(S[i]>='A' && S[i]<='Z')
- {
- top++;
- st[top]=(int)(S[i]-'A'+1);
- i++;
- }
- i--;
- }
- else if(S[i]==')')
- {
- suma=0;
- while(st[top]!=-1)
- {
- suma+=st[top];
- st[top]=0;
- top--;
- }
- st[top]=suma;
- }
- else if(S[i]>='0' && S[i]<='9')
- {
- int nr=0;
- while(S[i] && (S[i]>='0' && S[i]<='9'))
- nr=nr*10+(S[i]-48), i++;
- i--;
- st[top]=st[top]*nr;
- }
- }
- if(top==1)
- fout<<st[top];
- else
- {
- suma=0;
- for(int i=1; st[i]; i++)
- if(st[i]>0)
- suma+=st[i];
- fout<<suma;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement