fork(1) download
  1. /*
  2. Bismillahir Rahmanir Rahim
  3. Coder:
  4. */
  5.  
  6. #include <algorithm>
  7. #include <cctype>
  8. #include <cmath>
  9. #include <cstdio>
  10. #include <cstdlib>
  11. #include <cstring>
  12. #include <iostream>
  13. #include <map>
  14. #include <queue>
  15. #include <set>
  16. #include <sstream>
  17. #include <stack>
  18. #include <string>
  19. #include <vector>
  20. #include <fstream>
  21. #include <ctime>
  22.  
  23.  
  24. # define FOR(i, a, b) for (int i=a; i<b; i++)
  25. # define REP(i, a) FOR(i,0,a)
  26.  
  27. #define EPS 1e-11
  28. #define inf 1234567891
  29. #define LL long long
  30.  
  31. #define abs(x) (((x)< 0) ? (-(x)) : (x))
  32. #define all(x) (x).begin(), (x).end()
  33. #define ms(x, a) memset((x), (a), sizeof(x))
  34.  
  35. #define pb push_back
  36. #define FORIT(i,m) for(__typeof((m).begin()) i=(m).begin();i!=(m).end();i++)
  37. #define pii pair<int,int>
  38. #define UNIQUE(c) (c).resize( unique( all(c) ) - (c).begin() )
  39.  
  40. #define READ(f) {ifstream infile(f) ;if(infile.good()) freopen(f, "r", stdin);}
  41. #define WRITE(f) freopen(f, "w", stdout)
  42. #define CIN ios_base::sync_with_stdio(0);
  43. ///int rrr[]={1,0,-1,0};int ccc[]={0,1,0,-1}; //4 Direction
  44. ///int rrr[]={1,1,0,-1,-1,-1,0,1};int ccc[]={0,1,1,1,0,-1,-1,-1};//8 direction
  45. ///int rrr[]={2,1,-1,-2,-2,-1,1,2};int ccc[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
  46. ///int rrr[]={2,1,-1,-2,-1,1};int ccc[]={0,1,1,0,-1,-1}; //Hexagonal Direction
  47. ///int month[]={31,28,31,30,31,30,31,31,30,31,30,31}; //month
  48.  
  49. using namespace std;
  50.  
  51.  
  52. int main(){
  53.  
  54. int t, n, chk = 1;
  55. int i,j;
  56. char a='a';
  57. map<char,int>map1,map2;
  58. string s;
  59. for( i=1;i<=26;i++ )
  60. {
  61. scanf("%d",&n);
  62. map1[a]=n;
  63. a++;
  64. }
  65. cin.ignore();
  66. getline(cin,s);
  67. i=0;
  68. while( s[i]!='\0' )
  69. {
  70. ++map2[s[i]];
  71. i++;
  72. }
  73. i=0;
  74. int sum,c=0,flg,l=s.length(),m;
  75. char s1[1000];
  76. while( i<l-1 )
  77. {
  78. sum=0;
  79. m=0;
  80. if( map2[s[i]]>=2 )
  81. {
  82. //printf("%c",s[i]);
  83. s1[m++]=s[j];
  84. j=i+1;
  85. while(s[j]!=s[i])
  86. {
  87. s1[m++]=s[i];
  88. sum+=map1[ s[ j ] ];
  89. //printf("%c",s[j]);
  90. j++;
  91. }
  92. s1[m]='\0';
  93. printf("%s\n\n",s1);
  94. --map2[s[i]];
  95. if( !sum )
  96. {
  97.  
  98. ++c;
  99. }
  100. }
  101. i++;
  102. }
  103. printf("%d\n",c);
  104.  
  105. return 0;
  106. }
  107.  
Success #stdin #stdout 0s 3236KB
stdin
-2 -2 2 1 4 0 -2 4 5 4 -5 -5 2 1 1 -1 0 -5 -2 3 -2 4 5 2 3 -5
qgzhbkitmqwttdyoyvcbxincwjryzknubpacsngorexaldfurondbednowemnnlphhboycfavsovisrmfaefusoobingjhsmrukx
stdout
yqqqqqqqq

qgggggggggggggggggggggggggggggggggggg

gzzzzzzzzzzzzzzzzzzzzzzzzz

zhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

hbbbbbbbbbbbbbb

bkkkkkkkkkkkkkkkkkkkkkkk

kiiiiiiiiiiiiii

ittt

tmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm

mwwwwwwwwwwwww

w

tddddddddddddddddddddddddddddddd

dy

yooooooooooooooooooooooo

oyyyyyyyyyy

yvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

vcccc

cbbbbbbbbbbbb

bxxxxxxxxxxxxxxxxxxxxx

xiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii

innnnnnn

nccccccccccc

cwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww

wjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj

jrrrrrrrrrrrrr

ryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy

ykkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk

knnnnnn

nuuuuuuuuuuuuuuu

ubbbbbbbbbbbbbbbbbbb

bppppppppppppppppppppppppppppp

paaaaaaaa

accccccccccccccccccccccccccccccccc

cssssssssssssssssssssssssssssssssssss

snnnnnnnnnnnn

ngggggggggggggggggggggggggggggggggggggggggggggggggggg

gooooooooo

orrrrrrr

reeeeeeeeeee

exxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

xaaaaaaaaaaaaaaaaaaaaaaaaaaa

alllllllllllllllll

lddddd

dfffffffffffffffffffffff

fuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

urrrrrrrrrrrrrrrrrrrrrrrrrrrrr

roooooo

onnnn

ndd

dbbbbbbbbbbbbb

beeee

ennnn

noooooooooo

oeeeeeeeeeeeeeeeeeeeeeee

emmmmmmmmmmmmmmmmmmm

m

nnnnnnnnnnnnnnnnnnnnnnnnnnnnn

n

hhhhhhhhhhhhhhhhhhhhhhhhhhhh

hbbbbbbbbbbbbbbbbbbbbb

boooooo

offfffffff

faaaaaaaaa

avv

vsss

sooooooooooo

oiiiiiiiiiiii

isssssss

srrrrrrrrrrrrrrrrr

rmmmmmmmmmmmmmmm

mff

fuuuuuuuuuuuu

ussssssss

s

5