-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathstring formatting with replacement array.cpp
More file actions
82 lines (74 loc) · 1.72 KB
/
string formatting with replacement array.cpp
File metadata and controls
82 lines (74 loc) · 1.72 KB
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
78
79
80
81
82
#include<bits/stdc++.h>
#define MAX 100000
using namespace std;
map<int,string> convrttoarr(string s){
map<int,string> mymap;
string a="";
int count =0;
int len = s.length();
for(int i=0;i<len;++i)
{
string a="";
while(i<len && s[i]!=' ')
{
a+=s[i];
i++;
}
//cout<<i<<"--";
mymap[count]=a;
//cout<<mymap[count];
//i++;
count++;
}
return mymap;
}
int main(){
int n,t,i,j,temp,n1,n2,count_braces=0,k;
string rep_string, pos_string;
string ans="";
getline(cin,rep_string);
//cout<<rep_string;
getline(cin,pos_string);
//cout<<pos_string;
map<int,string> parsed= convrttoarr(rep_string);
int len= pos_string.length();
for(i=0;i<len;++i)
{
if(pos_string[i]=='{')
{
char index_string[1000];
k=0;
bool numeral=true;
++i;
while(pos_string[i]!='}')
{
if(isalpha(pos_string[i]))
{
numeral=false;
}
index_string[k]=pos_string[i];
k++;
i++;
}
if(k==0)
{
ans+=parsed[count_braces];
++count_braces;
}
else if(numeral==true)
{
int x=atoi(index_string);
ans+=parsed[x];
}
else if(numeral==false)
{
ans+=index_string;
}
//cout<<ans<<endl;
}
else
ans+=pos_string[i];
}
cout<<ans<<endl;
return 0;
}