p1821

样例输入 Sample Input 
3 3
1 A
2 B
3 C
5 6
1 A
2 B
5 B
1 C
2 A
2 B
8 8
4 V
3 I
7 T
7 A
6 R
5 N
1 O
9 H
样例输出 Sample Output  
!
B?A?C
HONITAVR

本题有两个要点:输出的顺序与"每个字母在转盘中只会出现一次";

然而它还是一道模拟题.开一个字符数组是当前转盘,now模拟指针,每次读入ci后now=(now+ci)%n,(这样转盘就被限制在了0到n-1之间).对于chi,如果当前now有了还不是chi就输出!,否则判断chi是否出现过,记录一下.

输出就从now到0,再从n-1到now+1即可.

其实memset本来的作用是给字符数组赋字符用的....

using namespace std;
int i,f,now,t;
int n,m,v[1000];
char ans[1000],tch;
int main()
{
//freopen("123.in","r",stdin);
//freopen("123.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
    while(cin>>n>>m)
    {
        memset(ans,'?',sizeof(ans));
        memset(v,-1,sizeof(v));
        now=0;
        for(i=1;i<=m;i++)
        {
            cin>>t>>tch;
            now=(now+t)%n;
            if(tch<0)
                exit(0);
            if(ans[now]!=tch)
            {
                if(ans[now]=='?'&&v[tch]==-1)
                    ans[now]=tch,v[tch]=now;
                else
                {
                    cout<<'!'<<endl;
                    break;
                }
            }
        }
        if(i!=m+1)
        {
            for(;i<m;i++)//i<m非常重要(最烦这种调不出来的错误了)
                cin>>t>>tch;
            continue;
        }
        for(i=now;i>=0;i--)
            cout<<ans[i];
        for(i=n-1;i>now;i--)
            cout<<ans[i];
        cout<<endl;
    }
    return 0;
}

 

posted @ 2018-10-05 20:12  zzuqy  阅读(153)  评论(0编辑  收藏  举报