Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我的想法是每次查询的时候,就回退找原来的插入操作,如果插入位置小于查询位置,查询位置--,如果等于查询位置就输出,为什么WA呢?

Posted by yiyiyi4321 at 2006-07-30 23:14:21 on Problem 2887
#include<stdio.h>

#define M 1000011
#define N 1011

char s[M],op[N][4],ch[N][4],ans;
int loc[N], i, j, n, len;

int main()
{
	gets(s);
	len = strlen(s);
	scanf("%d",&n);
	for(i = 0; i < n; i ++)
	{
		scanf("%1s",op[i]);
		if(op[i][0]=='Q')
		{
			scanf("%d",&loc[i]);
			ans='\0';
			for(j = i - 1; j >= 0; j -- )
			{
				if(op[j][0]=='I')
				{
					if(loc[j] < loc[i])loc[i]--;
					else if(loc[j] ==loc[i]){
						ans=ch[j][0];
						break;
					}
				}
			}
			if(ans=='\0')ans=s[loc[i]-1];
			putchar(ans);putchar('\n');
		}
		else if(op[i][0]=='I')
		{
			scanf("%1s%d",ch[i],&loc[i]);
			if(loc[i] > len)loc[i] = len + 1;
			len ++;
		}
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator