BNUOJ 3013 Ancient Keyboard

Ancient Keyboard

1000ms
65536KB
This problem will be judged on PKU. Original ID: 2894
64-bit integer IO format: %lld      Java class name: Main
Font Size:
Type:
The scientists have found an ancient device that works in a strange way. The device has a keyboard and an output tape. The keyboard has 26 keys, with symbols 'A' through 'Z' on them. Each key has an LED on it (like the Caps Lock key on some keyboards). Each time you press a key, the LED on it toggles (changes its state from off to on or vice versa). All LEDs are off initially.

To study the output written on the tape, we consider the device in discrete time steps. Suppose we are in time t. If no LED is on, no output is written on the tape. If there are i LEDs on, the ith letter of the English alphabet is written on the tape. For example, if three LEDs are on at a time step, a letter 'C' is written on the tape. This process repeats at every time step.

You are asked to write a program that simulates the ancient device.

Input

The input contains multiple test cases. The first line of the input, contains t, the number of test cases that follow. Each of the following t blocks, describes a test case.

The first line of each block contains one integer n (0 <= n <= 26). After this, there are n lines, each containing one capital alphabet letter, followed by two integers a and b, (0 <= a < b <= 1000). The capital letter shows the key pressed. The number a is the first time step at which the key is pressed and the number b is the second time step at which the key is pressed. During the interval a, a + 1, . . . , b -1, theLED of the key is on. You can assume that, in each test case, these letters are distinct.

Output

For each test case, output one line containing the output string that is written on the tape.

Sample Input

2
2
X 2 6
Y 4 9
3
A 1 5
B 4 8
C 9 10

Sample Output

AABBAAA
AAABAAAA

 

 

很水的一道题,但是因为少考虑了一种情形,wa了好多次。。。

注意:输入的不同行的a b 可能相同。。。

#include<stdio.h>
struct node{
    char c;
 int p; 
}s[60];
int f[1005];
int main()
{
 int i,j,a,b,k,h,t,n,min,max;
 char ch;
 while(scanf("%d",&t)!=EOF)
 {
  while(t--){
   memset(s,0,sizeof(s));
      scanf("%d",&n);  k=0;
      min=2000; max=0;
   for(i=0;i<n;i++){
       getchar();
    scanf("%c %d %d",&ch,&a,&b);
    min=a<min?a:min;
    max=b>max?b:max;
    s[k].c=ch;   s[k++].p=a;
    s[k].c=ch;   s[k++].p=b;
   } 
   for(i=0;i<26;i++)  f[i]=-1;
   for(i=min;i<=max;i++){
    h=0;
       for(j=0;j<k;j++){
        if(s[j].p==i)  f[s[j].c-'A']=-f[s[j].c-'A']; 
    }
    for(j=0;j<26;j++)
        if(f[j]==1)  h++;
    if(h)  printf("%c",h-1+'A'); 
   }
   printf("\n");
  }
 }
    system("pause");
 return 0; 
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值