-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp
77 lines (74 loc) · 1.53 KB
/
temp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include<string>
#include<sstream>
using namespace std;
int main() {
int i=0,x=0,j,count=0,k=0,y=0;
string a,b,c[1000],d,e,res="";
getline(cin,a);
getline(cin,b);
istringstream ss(a);
while(ss>>d)
{
c[i++]=d;count++;
}i=0;
istringstream sb(b);
while(sb>>d){
//k=y=j=x=0;
if(d[0]=='%')
{
if(d[1]=='s')
if(d.length()==2){
if(i<count)
res+=c[i++];
else res+=d;
}
else if(d.length()>2&&d[2]!='['&&d[2]!=':')
res+=c[i++]+d.substr(2,d.size()-1);
else if(d[2]=='[')
{if('0'<=d[3]<='9')
{j=3;
while(d[j]!=']'&&'0'<=d[j]&&d[j]<='9')
{
x=x*10+(d[j]-'0');
j++;
}
if(d[j]==']'&&j==d.size()-1)
{res+=c[x];x=0;}
else if(d.size()>j+1&&d[j+1]==':')
{
k=j+2;y=0;
while(k<d.size())
{
y=y*10+(d[k]-'0');
k++;
}
if(y<c[x].size())
res+=c[x].substr(0,y);
else res+=c[x];
//else res+=d;
y=0;
}
else res+=d;
}
else res+=d;
}
else if(d[2]==':')
{k=3;y=0;
while(k<d.size())
{
y=y*10+(d[k]-'0');
k++;
}
if(k<c[i].size())
res+=c[i++].substr(0,k-1);
else res+=c[i++];
y=k=0;
}
}
else res+=d;
res+=' ';
}
cout<<res;
return 0;
}