PersonalCorpus 版 (精华区)

寄信人: sino (蚱蜢舟)
标  题: 101
发信站: 哈工大紫丁香 (2002年03月15日16:03:57 星期五)
来  源: mtlab4.hit.edu.cn 

783929 2002/03/15 08:04:06.974
Bozhang ,HIT,P.R.China ... 101 C++ Accepted 0:00.030 64

void ReadLn(char *s)
{
    int i=0;
    char c;
    while (scanf("%c",s+i)==1) {
        if (s[i]=='\n') { s[i]=0; return; } else i++;
    }
}
void main()
{
    int i,j,k,n,a,b;
    int st[25][26],line[25];
    char s[100],*t,*r;
    scanf("%d\n",&n);
    ReadLn(s);
    for (i=0;i<n;i++) { st[i][0]=1; st[i][1]=i; line[i]=i; }
    while (s[0]!='q') {
        if (s[0]=='m') {
            i=5; while (s[i]==' ') i++;
            a=0; while (s[i]!=' ') { a*=10; a+=s[i]-48; i++; }
            while (s[i]==' ') i++; i++;
            if (s[i]=='n') {
                i+=4;  while (s[i]==' ') i++;
                b=0; while ((s[i]!=0)&&(s[i]!=' ')) { b*=10;b+=s[i]-48;i++; }
                // move a onto b
                if ((a==b)||(line[a]==line[b])) { ReadLn(s); continue; }
                i=st[line[a]][0];
                while ((st[line[a]][i]!=a)&&(i>0)) {
                    st[line[a]][0]--;
                    st[st[line[a]][i]][0]=1;
                    st[st[line[a]][i]][1]=st[line[a]][i];
                    line[st[line[a]][i]]=st[line[a]][i];
                    i--;
                }
                st[line[a]][0]--;
                line[a]=line[b];
                i=st[line[b]][0];
                while ((st[line[b]][i]!=b)&&(i>0)) {
                    st[line[b]][0]--;
                    st[st[line[b]][i]][0]=1;
                    st[st[line[b]][i]][1]=st[line[b]][i];
                    line[st[line[b]][i]]=st[line[b]][i];
                    i--;
                }
                st[line[b]][0]++;
                st[line[b]][st[line[b]][0]]=a;
            } else {
                i+=4;  while (s[i]==' ') i++;
                b=0; while ((s[i]!=0)&&(s[i]!=' ')) { b*=10;b+=s[i]-48;i++; }
                // move a over b
                if ((a==b)||(line[a]==line[b])) { ReadLn(s); continue; }
                i=st[line[a]][0];
                while ((st[line[a]][i]!=a)&&(i>0)) {
                    st[line[a]][0]--;
                    st[st[line[a]][i]][0]=1;
                    st[st[line[a]][i]][1]=st[line[a]][i];
                    line[st[line[a]][i]]=st[line[a]][i];
                    i--;
                }
                st[line[a]][0]--;
                line[a]=line[b];
                st[line[b]][0]++;
                st[line[b]][st[line[b]][0]]=a;
            }
        } else {
            i=5; while (s[i]==' ') i++;
            a=0; while (s[i]!=' ') { a*=10; a+=s[i]-48; i++; }
            while (s[i]==' ') i++; i++;
            if (s[i]=='n') {
                i+=4;  while (s[i]==' ') i++;
                b=0; while ((s[i]!=0)&&(s[i]!=' ')) { b*=10;b+=s[i]-48;i++; }
                // pile a onto b
                if ((a==b)||(line[a]==line[b])) { ReadLn(s); continue; }
                i=st[line[b]][0];
                while ((st[line[b]][i]!=b)&&(i>0)) {
                    st[line[b]][0]--;
                    st[st[line[b]][i]][0]=1;
                    st[st[line[b]][i]][1]=st[line[b]][i];
                    line[st[line[b]][i]]=st[line[b]][i];
                    i--;
                }
                for (i=1;i<=st[line[a]][0];i++) if (st[line[a]][i]==a) break;
                k=line[a];
                while (i<=st[k][0]) {
                    st[line[b]][0]++;
                    st[line[b]][st[line[b]][0]]=st[k][i];
                    line[st[k][i]]=line[b];
                    i++;
                }
                for (i=1;i<=st[k][0];i++) if (st[k][i]==a) break;
                st[k][0]=i-1;
            } else {
                i+=4;  while (s[i]==' ') i++;
                b=0; while ((s[i]!=0)&&(s[i]!=' ')) { b*=10;b+=s[i]-48;i++; }
                //pile a over b
                if ((a==b)||(line[a]==line[b])) { ReadLn(s); continue; }
                for (i=1;i<=st[line[a]][0];i++) if (st[line[a]][i]==a) break;
                k=line[a];
                while (i<=st[k][0]) {
                    st[line[b]][0]++;
                    st[line[b]][st[line[b]][0]]=st[k][i];
                    line[st[k][i]]=line[b];
                    i++;
                }
                for (i=1;i<=st[k][0];i++) if (st[k][i]==a) break;
                st[k][0]=i-1;
            }
        }
        ReadLn(s);
    }
    for (i=0;i<n;i++) {
        printf("%d:",i);
        for (j=1;j<=st[i][0];j++) printf(" %d",st[i][j]);
        printf("\n");
    }
}

--
FreeBSD has a large number of afficionados who are prepared  to flame 
anybody who  dares  suggest that it's not better than Linux.

Linux has a large number of afficionados who  are  prepared  to flame 
anybody who dares suggest that it's not better than FreeBSD.

※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: mtlab4.hit.edu.cn]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:4.004毫秒