fork(1) download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. String line;
  8. line=Console.ReadLine();
  9. long[] cnt = new long[26];
  10. for(int i = 0;i<26;i++)
  11. cnt[i] = 0;
  12. char c = 'a';
  13. char b;
  14. int st = 0;
  15. int pt = 0;
  16. int n;
  17. long a = 1;
  18. long[] ar = new long[256];
  19. for(int i = 0;i<256;i++)
  20. ar[i] = 1;
  21.  
  22. for(int i = 0;i<line.Length;i++){
  23. if(Int32.TryParse(line.Substring(i, 1), out n)){
  24. st = i;
  25. while(Int32.TryParse(line.Substring(i+1, 1), out n))
  26. i++;
  27. //Console.WriteLine(line.Substring(st, i-st+1));
  28. Console.Write(i-st+1);
  29. a *= Int32.Parse(line.Substring(st, i-st+1));
  30. Console.WriteLine(st + "to" + i + "=" + a);
  31. ar[pt] = a;
  32. }
  33. else if(line[i] == '('){
  34. pt++;
  35. }
  36. else if(line[i] == ')'){
  37. pt--;
  38. if(ar[pt] == 0){
  39. a = 1;
  40. Console.WriteLine(pt + ":" + ar[pt] + " " + i);
  41. }
  42. else
  43. a /= ar[pt];
  44. //Console.WriteLine(ar[pt]);
  45. ar[pt] = 1;
  46. }
  47. else{
  48. b = line[i];
  49. cnt[b-c] += a;
  50. if(ar[pt] == 0){
  51. a = 1;
  52. Console.WriteLine(pt + ":" + ar[pt] + " " + i);
  53. }
  54. else
  55. a /= ar[pt];
  56. //Console.WriteLine(ar[pt]);
  57. ar[pt] = 1;
  58. }
  59. }
  60. for(int i = 0;i<26;i++){
  61. Console.WriteLine((char)(c+i) + " " + cnt[i]);
  62. }
  63. }
  64. }
Success #stdin #stdout 0.01s 131648KB
stdin
abcdefg10h12(ij2(3k))l9mnop4(3(2(6(qq)r)s5tu)7v5w)x15(yz)
stdout
27to8=10
210to11=12
115to15=24
117to17=72
122to22=0
0:0 23
127to27=4
129to29=12
131to31=24
133to33=144
141to41=0
2:0 42
145to45=0
1:0 46
147to47=5
251to52=0
0:0 56
a 1
b 1
c 1
d 1
e 1
f 1
g 1
h 10
i 12
j 12
k 72
l 0
m 0
n 1
o 1
p 1
q 288
r 1
s 0
t 0
u 1
v 0
w 5
x 0
y 0
z 0