When the size of the array is not known before hand. The vector is used and character wise input is taken and integers and floats are created.
#include<cstdio> #include<vector> #include<algorithm> using namespace std; int main(){ int T; scanf("%d", &T); getchar();getchar(); char c, int_s[12]; int i = 0; vector<int> p; while(true){ c = getchar(); if(c==' '){ int_s[i] = '\0'; i = 0; p.push_back(atoi(int_s)); } else if(c=='\n'){ int_s[i] = '\0'; i = 0; p.push_back(atoi(int_s)); break; } else{ int_s[i++] = c; } } float A[p.size()]; float B[p.size()]; for(int j = 0; j<p.size(); j++){ scanf("%f", A+j); } for(int j = 0; j<p.size(); j++){ B[p[j]-1] = A[j]; } for(int j = 0; j<p.size(); j++){ printf("%f\n", B[j]); } return 0; }
Note: Verdict is not accepted, because of some stupid bug. The main thing to learn is to get the input in the required format.