Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
奇怪的RE自己查了很久也找不到那里弄到RE,空行的情况也考虑了,而且在ZOJ也AC了,哪位高手帮忙看一下 #include <string.h> #include <stdio.h> #include <stdlib.h> #include <vector> using namespace std; vector<int> a[60]; char* line,*lp; int n,temp,i,j,tpnum,ll; bool flag[60]; int pcode[60]; void process() { bool tflag[60]; int j,k; for (j=1; j<=n-1; j++) { memset(tflag,0,sizeof(tflag)); tflag[pcode[j]]=true; for (k=j+1; k<=n-1; k++) tflag[pcode[k]]=true; for (k=1; k<=n; k++) if (tflag[k]==false && flag[k]==false) { a[pcode[j]].push_back(k); flag[k]=true; break; } } } void printans(int v) { int iter,g,k; printf("(%d",v); if (a[v].size()!=0) printf(" "); k=a[v].size(); for (iter=0; iter<=k-1; iter++) { g=a[v][iter]; printans(g); if (iter!=k-1) printf(" "); } printf(")"); } void readline() { int li,lv; int numl; lv=strlen(line); n=0; numl=0; for (li=0; li<lv; li++) { if (line[li]!=' ') numl=numl*10+(line[li]-'0'); else { pcode[++n]=numl; numl=0; } } pcode[++n]=numl; ++n; } int main() { //freopen("1965.txt","r",stdin); line=new char[120]; while(gets(line)) { if (strcmp(line,"")==0) { printf("(1)\n"); continue; } memset(flag,0,sizeof(flag)); memset(pcode,0,sizeof(pcode)); readline(); for (i=1; i<=n; i++) a[i].resize(0); process(); printans(pcode[n-1]); printf("\n"); strcpy(line,""); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator