uva 482 - Permutation Arrays

时间:2023-03-09 08:02:01
uva 482 - Permutation Arrays

<int, double> --> <int, string> 从而避免了输出格式;

 #include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>
using namespace std; int main()
{
int t, count = ;
string line1, line2;
int index;
string value;
vector<pair<int, string>> store;
cin >> t;
getchar();
while(t--)
{
getchar();
count ++;
getline(cin, line1);
getline(cin, line2);
stringstream ss1(line1), ss2(line2);
while(ss1 >> index)
{
ss2 >> value;
store.push_back(pair<int, string>(index, value));
}
sort(store.begin(), store.end());
if(count > ) cout << endl;
for(int i = ; i < store.size(); i++)
cout << store[i].second << endl; store.clear();
} return ;
}
 #include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
using namespace std; int main()
{
int T;
cin >> T;
while(T--)
{
string str, s;
stringstream ss;
vector<int> ind;
map<int, string> Map; getline(cin, str); // T 后面的\n
getline(cin, str); // 空行 getline(cin, str); // index
ss << str;
while(ss >> s) ind.push_back(stoi(s)); for(int i= ;i < ind.size(); i++)
cin >> str, Map[ind[i]] = str; for(int i = ; i < ind.size(); i++)
cout << Map[i+] << endl;
if(T > )
cout << endl;
}
return ;
} string toString(int I)
{
stringstream ss;
string str;
ss << I;
ss >> str; return str;
}
 // 输入输出是怎么回事???
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map> using namespace std; #define FOI(i, A, B) for(i = A; i <= B; i++)
#define FOD(i, A, B) for(i = A; i >= b; i--) string toString(int I)
{
stringstream ss;
string str;
ss << I;
ss >> str; return str;
} int main()
{
int T;
cin >> T;
string str, s;
while(T--)
{
getline(cin, str);
getline(cin, str);
vector<string> ind, val;
map<string, string> Map;
stringstream ss;
getline(cin, str);
ss << str;
while(ss >> s) ind.push_back(s);
int N = ind.size(), i;
FOI(i, , N-)
{
cin >> str;
Map[ind[i]] = str;
}
FOI(i, , N-)
cout << Map[toString(i+)] << endl;
if(T > )
cout << endl;
}
return ;
}