Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 511????Accepted Submission(s): 216
?
Input The first line contains an integer T(T<=20), indicating the number of test cases.?
Output For each case, you should output the detailed log.?
Sample Input3 walpurgis(charlotte(patricia,gertrud),elly,gisela) wuzetian nanoha(fate(hayate))
?
Sample Output6 walpurgis charlotte patricia gertrud elly gisela 1 2 2 3 3 2 2 4 4 2 2 1 1 5 5 1 1 6 6 1 1 wuzetian 3 nanoha fate hayate 1 2 2 3 3 2 2 1?
????????? 题目大意:水题!模拟题!英语题!不解释,直接代码。遇到这些题就是要小心啊!不要粗心大意!
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4041
代码:
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <string>
#include <stack>
using namespace std;
char str[1000005], ss[1000005];
char sh[105];
char ch[50005][105];
int main()
{
int i, k, len, t, ans, num;
bool tar;
scanf("%d", &t);
while(t--)
{
stack<int> ST;
scanf("%s", str);
len = strlen(str);
tar = true;
num = 0;
ans = 0;
for(i = 0; i < len; i++)
{
if(str[i]>='a' && str[i]<='z')
{
sh[ans++] = str[i];
tar = false;
}
else
{
if(tar) continue;
sh[ans] = 0;
strcpy(ch[num], sh);
num++;
ans = 0;
tar = true;
}
}
if(!tar)
{
sh[ans] = 0;
strcpy(ch[num], sh);
num++;
}
printf("%d\n", num);
for(i = 0; i < num; i++)
{
printf("%s\n", ch[i]);
}
k = 1;
for (i = 0; i < len; i++)
{
if(str[i] == '(') continue;
if(str[i] >= 'a' && str[i] <= 'z' && (i+1 >= len || str[i+1] < 'a' || str[i+1] > 'z'))
{
if(ST.size() > 0)
printf ("%d %d\n", ST.top(), k);
ST.push(k++);
}
if(str[i] == ',' || str[i] == ')')
{
printf("%d ", ST.top());
ST.pop();
printf("%d\n", ST.top());
}
}
printf ("\n");
}
return 0;
}
?