CSU

https://cn.vjudge.net/contest/157163#problem/E

#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<cstdio>
#include<sstream>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include <ctype.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std;

typedef long long ll;
const int maxn=1100;
const int INF=0x3f3f3f3f;


int t,n,m;
int main()
{
    int i;
    scanf("%d",&t);
    string a;
    map<int,string>s;
    for(int i=1; i<=t; i++)
    {
        cin>>a;
        s[i]=a;
    }
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        int j,v;
        int l=INF,r=INF;
        scanf("%d",&m);
        if(s[m]!="?")
            cout<<s[m]<<endl;
        else if(s[m]=="?")
        {
            for(j=m-1; j>=1; j--)
            {
                if(s[j]!="?")
                {
                    l=m-j;
                    break;
                }
            }
            for(v=m+1; v<=t; v++)
            {
                if(s[v]!="?")
                {
                    r=v-m;
                    break;
                }
            }
            if(l==r)
                cout<<"middle of "<<s[j]<< " and "<<s[v]<<endl;
            else if(l>r)
            {
                for(int k=1; k<=r; k++)
                    printf("left of ");
                cout<<s[v]<<endl;
            }
            else
            {
                for(int k=1; k<=l; k++)
                    printf("right of ");
                cout<<s[j]<<endl;
            }
        }
    }
    return 0;
}



//int main()
//{
//    int t;
//    char str[maxn][4];
//    int n,m,i,left,right,num;
//    scanf("%d",&t);
//    for(i=0; i<t; i++)
//        scanf("%s",str[i]);
//    scanf("%d",&n);
//    while(n--)
//    {
//        scanf("%d",&m);
//        m--;
//        if(str[m][0]!='?')
//            printf("%s
",str[m]);
//        else
//        {
//            left=m;
//            right=m;
//            while(str[left][0]=='?'&&str[right][0]=='?')
//            {
//                if(left>0)
//                    left--;
//                if(right<t-1)
//                    right++;
//            }
//
//            if(str[left][0]!='?'&&str[right][0]!='?')
//                printf("middle of %s and %s
",str[left],str[right]);
//            else if(str[left][0]!='?')
//            {
//                num=m-left;
//                for(i=0; i<num; i++)
//                    printf("right of ");
//                printf("%s
",str[left]);
//            }
//            else
//            {
//                num=right-m;
//                for(i=0; i<num; i++)
//                    printf("left of ");
//                printf("%s
",str[right]);
//            }
//        }
//    }
//    return 0;
//}

原文地址:https://www.cnblogs.com/nyist-xsk/p/7264831.html