Question 1

12 comments on “Question 1”


  • shaikhafeez2002

    #include
    using namespace std;
    int main(){
    int n;
    cin>>n;
    int a[n],p[n];
    for(int i=1;i>a[i];
    }
    for(int i=1;i<=n;i++){
    p[a[a[i]]]=i;
    }
    for(int i=1;i<=n;i++){
    cout<<p[i]<<endl;
    }
    }


  • chlsaivarma186

    #include

    using namespace std;

    int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=1;i>a[i];
    }
    for(int x=1;x<=n;x++){
    for(int y=1;y<=n;y++){
    if(a[a[y]]==x){
    cout<<y<<endl;
    }
    }
    }
    return 0;
    }


  • Krishna

    #include
    using namespace std;

    int main() {
    int n, a, temp;
    cin >> n;
    map p;

    for (int i = 0, x = 1; i > a;

    if (a <= n) {
    p.insert({x,a});}

    else {
    exit(0);}}

    for (int i = 0, x = 1; i < n; i++, x++) {

    for (auto & ch: p){
    if (ch.second == x){
    temp = ch.first;}}

    for (auto & done: p){
    if (done.second == temp){
    cout << done.first << " ";}}}

    return 0;}


  • Krishna

    #include

    using namespace std;

    int main() {
    int n, a, temp;
    cin >> n;
    map p;

    for (int i = 0, x = 1; i > a;
    if (a <= n) {
    p.insert({x,a});
    } else {
    exit(0);
    }
    }

    for (int i = 0, x = 1; i < n; i++, x++) {
    for (auto & ch: p) {
    if (ch.second == x) {
    temp = ch.first;
    }
    }

    for (auto & done: p) {
    if (done.second == temp) {
    cout << done.first << " ";
    }
    }
    }

    return 0;
    }


  • Avipsha

    #include
    using namespace std;
    int main()
    {
    int n, i, x, j;
    cin >> n;
    int arr[n];
    for (i = 1; i > arr[i];
    }
    for (x = 1; x <= n; x++)
    {
    for (i = 1; i <= n; i++)
    {
    if (arr[i] == x)
    {
    for (j = 1; j <= n; j++)
    {
    if (arr[j] == i)
    {
    cout << j << endl;
    }
    }
    }
    }
    }
    }


  • abhitejkumarvoruganti

    a=int(input())
    p = list(map(int, input().rstrip().split()))
    for i in range(1,a+1):
    for j in range(len(p)):
    if p[j]==i:
    k=j+1
    for w in range(a):
    if p[w]==k:
    print(w+1)
    break
    break


  • vamsi krishna

    Below code also works fine
    n=int(input())
    arr=[int(x) for x in input().split()]
    map={}
    for i in range(n):
    map[arr[i]]=i
    x=[]
    for i in range(1,n+1):
    k=map[i]+1
    x.append(map[k]+1)
    print(x)


  • Ashutosh

    /*Solve the Equation
    Given a sequence of n integers p(1), p(2),…p(n), where each element is distinct and satisfies 1<=p(x)<=n. For each x where 1<=x<=n, find any integer y such that p(p(y))=x and print the value of y on a new line.

    Function Description

    Complete the Equation function in the editor below. It should return an array of integers that represent the values of y
    The equation has the following parameter(s):

    p: an array of integers
    Input Format

    The first line contains an integer n, the number of elements in the sequence.
    The second line contains n space-separated integers p[i] where 1<=i<=n.

    Output Format

    For each x from 1 to n, print an integer denoting any valid y satisfying the equation p(p(y)) on a new line.

    Sample Input

    3

    2 3 1

    Sample Output

    2

    3

    1*/

    #include
    using namespace std;

    int main()
    {
    int n;
    cin>>n;

    int arr[n+1];
    for(int i=1;i>arr[i];
    }
    for(int x=1;x<=n;x++)
    {
    int y=arr[arr[x]];

    cout<<y;
    }

    }


  • Pratik

    simple python solution:
    def permutationEquation:
    result = []
    n = len(p)
    for i in range (1, n+1):
    result.append(p.index(p.index(i)+1)+1)
    return result

    n = int(input(n))
    p = list(map(int, input().rstrip().split()))

    res = permutationEquation(p)
    for i in res:
    print(i)


  • Vinayak

    #include

    int main()
    {
    int n=0,p,y;
    scanf(“%d”,&n);
    int a[n+1];
    for(int i=1;i<=n;i++)
    {
    scanf("%d",&p);
    a[p]=i;

    }
    for(int j=1;j<=n;j++)
    {
    y=a[a[j]];
    printf("%d",y);
    }
    return 0;
    }


  • Snehal

    import java.util.*;
    public class Main
    {
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int p[] = new int[n+1];
    for(int i=1;i<=n;i++){
    int px=sc.nextInt();
    p[px] = i;
    }
    for(int x=1;x<=n;x++){
    int y = p[p[x]];
    System.out.println(y);
    }
    }
    }


  • Debparna

    import java.util.*;
    public class Main
    {
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String str = sc.nextLine();
    int N = Integer.parseInt(str);
    int arr[] = new int[N+1];
    int arrI[] = new int[N+1];
    str = sc.nextLine();
    String list[] = str.split(” “);
    boolean cond = true;
    if(list.length > N){
    System.out.println(“Invalid Input”);
    }else{
    int val = 0;
    for(int i=0;i<N;i++){
    val = Integer.parseInt(list[i]);
    arr[i+1] = val;
    }
    for(int i=1;i N){
    cond = false;
    break;
    }
    arrI[arr[i]] = i;
    }
    if(!cond){
    System.out.println(“Invalid Input”);
    }else{
    for(int i=1;i<=N;i++){
    System.out.println(arrI[arrI[arr[i]]]);
    }
    }
    }
    }
    }