1 solutions

  • 0
    @ 2025-11-5 17:17:52

    C++ :

    #include <stdio.h>
    int main()  
    {  
       //freopen("test.in.txt","r",stdin);
       //freopen("test.out","w",stdout); 
       int n,i,j,k,m,y;   
       while(scanf("%d",&n)!=EOF&&n!=0)
       {  
          int a[n];  
          int b[n];   
          char c;  
          for(i=0;i<n;i++)  
                b[i]=0;  
            scanf("%c",&c); 
          for(i=0;i<n;i++)  
              scanf("%d",&a[i]); 
          if(c=='P')  
          {  
              for(i=0;i<n;i++)  
                {  
                    k=i+1;  
                    y=0;  
                    while(k--)  
                    {
                        if(a[i]<a[k])  
                            y++;
    					}
                    b[a[i]-1]=y;  
                }  
                for(i=0;i<=n-1;i++)  
                {  
                    if(i==0)  
                        printf("%d",b[i]); 
                    else  
                         printf(" %d",b[i]); 
                }  
               printf("\n");    
          }  
          else if(c=='I')  
          {   
              for(i=0;i<n;i++)  
                {  
                    j=0;   
                    k=i+1;  
                    m=a[i];   
                    while(m+1)  
                    {   
                        if(b[j]==0)  
                            m--;  
                        j++;  
                    }   
                    b[j-1]=k;   
                }  
                for(i=0;i<n;i++)  
                {  
                    if(i==0)  
                        printf("%d",b[i]); 
                    else  
                        printf(" %d",b[i]); 
                }  
                 printf("\n");    
          }                        
       }  
       return 0;    
    }   
    
    
    • 1

    Information

    ID
    18265
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By