Ancient Keyboard
64-bit integer IO format: %lld Java class name: Main
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 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
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;
}