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 |
机子上好好的,怎么就废了?麻烦各位看一看: (用C,很长!但重复部分不会错) #include<stdio.h> #include<string.h> void judge(char s[],int stack[],int num[]) {int top=0,len,i,top2=0; len=strlen(s); for(i=0;i<len;i++) if(s[i]=='A'){stack[++top]=0;stack[++top]=1;num[++top2]=2;} else if(s[i]=='B'){stack[++top]=1;stack[++top]=0;stack[++top]=0;stack[++top]=0;num[++top2]=4;} else if(s[i]=='C'){stack[++top]=1;stack[++top]=0;stack[++top]=1;stack[++top]=0;num[++top2]=4;} else if(s[i]=='D'){stack[++top]=1;stack[++top]=0;stack[++top]=0;num[++top2]=3;} else if(s[i]=='E'){stack[++top]=0;num[++top2]=1;} else if(s[i]=='F'){stack[++top]=0;stack[++top]=0;stack[++top]=1;stack[++top]=0;num[++top2]=4;} else if(s[i]=='G'){stack[++top]=1;stack[++top]=1;stack[++top]=0;num[++top2]=3;} else if(s[i]=='H'){stack[++top]=0;stack[++top]=0;stack[++top]=0;stack[++top]=0;num[++top2]=4;} else if(s[i]=='I'){stack[++top]=0;stack[++top]=0;num[++top2]=2;} else if(s[i]=='J'){stack[++top]=0;stack[++top]=1;stack[++top]=1;stack[++top]=1;num[++top2]=4;} else if(s[i]=='K'){stack[++top]=1;stack[++top]=0;stack[++top]=1;num[++top2]=3;} else if(s[i]=='L'){stack[++top]=0;stack[++top]=1;stack[++top]=0;stack[++top]=0;num[++top2]=4;} else if(s[i]=='M'){stack[++top]=1;stack[++top]=1;num[++top2]=2;} else if(s[i]=='N'){stack[++top]=1;stack[++top]=0;num[++top2]=2;} else if(s[i]=='O'){stack[++top]=1;stack[++top]=1;stack[++top]=1;num[++top2]=3;} else if(s[i]=='P'){stack[++top]=0;stack[++top]=1;stack[++top]=1;stack[++top]=0;num[++top2]=4;} else if(s[i]=='Q'){stack[++top]=1;stack[++top]=1;stack[++top]=0;stack[++top]=1;num[++top2]=4;} else if(s[i]=='R'){stack[++top]=0;stack[++top]=1;stack[++top]=0;num[++top2]=3;} else if(s[i]=='S'){stack[++top]=0;stack[++top]=0;stack[++top]=0;num[++top2]=3;} else if(s[i]=='T'){stack[++top]=1;num[++top2]=1;} else if(s[i]=='U'){stack[++top]=0;stack[++top]=0;stack[++top]=1;num[++top2]=3;} else if(s[i]=='V'){stack[++top]=0;stack[++top]=0;stack[++top]=0;stack[++top]=1;num[++top2]=4;} else if(s[i]=='W'){stack[++top]=0;stack[++top]=1;stack[++top]=1;num[++top2]=3;} else if(s[i]=='X'){stack[++top]=1;stack[++top]=0;stack[++top]=0;stack[++top]=1;num[++top2]=4;} else if(s[i]=='Y'){stack[++top]=1;stack[++top]=0;stack[++top]=1;stack[++top]=1;num[++top2]=4;} else if(s[i]=='Z'){stack[++top]=1;stack[++top]=1;stack[++top]=0;stack[++top]=0;num[++top2]=4;} else if(s[i]=='_'){stack[++top]=0;stack[++top]=0;stack[++top]=1;stack[++top]=1;num[++top2]=4;} else if(s[i]==','){stack[++top]=0;stack[++top]=1;stack[++top]=0;stack[++top]=1;num[++top2]=4;} else if(s[i]=='.'){stack[++top]=1;stack[++top]=1;stack[++top]=1;stack[++top]=0;num[++top2]=4;} else if(s[i]=='?'){stack[++top]=1;stack[++top]=1;stack[++top]=1;stack[++top]=1;num[++top2]=4;} } int work(int u) {char s[1000]; int l,i; scanf("%s",s); int stack[1000],num[1000],top=0; judge(s,stack,num); l=strlen(s); printf("%d: ",u); for(i=l;i>=1;i--) if((num[i]==2)&&(stack[top+1]==0)&&(stack[top+2]==1)) {top=top+num[i];printf("A");} else if((num[i]==4)&&(stack[top+1]==1)&&(stack[top+2]==0)&&(stack[top+3]==0)&&(stack[top+4]==0)) {top=top+num[i];printf("B");} else if((num[i]==4)&&(stack[top+1]==1)&&(stack[top+2]==0)&&(stack[top+3]==1)&&(stack[top+4]==0)) {top=top+num[i];printf("C");} else if((num[i]==3)&&(stack[top+1]==1)&&(stack[top+2]==0)&&(stack[top+3]==0)) {top=top+num[i];printf("D");} else if((num[i]==1)&&(stack[top+1]==0)) {top=top+num[i];printf("E");} else if((num[i]==4)&&(stack[top+1]==0)&&(stack[top+2]==0)&&(stack[top+3]==1)&&(stack[top+4]==0)) {top=top+num[i];printf("F");} else if((num[i]==3)&&(stack[top+1]==1)&&(stack[top+2]==1)&&(stack[top+3]==0)) {top=top+num[i];printf("G");} else if((num[i]==4)&&(stack[top+1]==0)&&(stack[top+2]==0)&&(stack[top+3]==0)&&(stack[top+4]==0)) {top=top+num[i];printf("H");} else if((num[i]==2)&&(stack[top+1]==0)&&(stack[top+2]==0)) {top=top+num[i];printf("I");} else if((num[i]==4)&&(stack[top+1]==0)&&(stack[top+2]==1)&&(stack[top+3]==1)&&(stack[top+4]==1)) {top=top+num[i];printf("J");} else if((num[i]==3)&&(stack[top+1]==1)&&(stack[top+2]==0)&&(stack[top+3]==1)) {top=top+num[i];printf("K");} else if((num[i]==4)&&(stack[top+1]==0)&&(stack[top+2]==1)&&(stack[top+3]==0)&&(stack[top+4]==0)) {top=top+num[i];printf("L");} else if((num[i]==2)&&(stack[top+1]==1)&&(stack[top+2]==1)) {top=top+num[i];printf("M");} else if((num[i]==2)&&(stack[top+1]==1)&&(stack[top+2]==0)) {top=top+num[i];printf("N");} else if((num[i]==3)&&(stack[top+1]==1)&&(stack[top+2]==1)&&(stack[top+3]==1)) {top=top+num[i];printf("O");} else if((num[i]==4)&&(stack[top+1]==0)&&(stack[top+2]==1)&&(stack[top+3]==1)&&(stack[top+4]==0)) {top=top+num[i];printf("P");} else if((num[i]==4)&&(stack[top+1]==1)&&(stack[top+2]==1)&&(stack[top+3]==0)&&(stack[top+4]==1)) {top=top+num[i];printf("Q");} else if((num[i]==3)&&(stack[top+1]==0)&&(stack[top+2]==1)&&(stack[top+3]==0)) {top=top+num[i];printf("R");} else if((num[i]==3)&&(stack[top+1]==0)&&(stack[top+2]==0)&&(stack[top+3]==0)) {top=top+num[i];printf("S");} else if((num[i]==1)&&(stack[top+1]==1)) {top=top+num[i];printf("T");} else if((num[i]==3)&&(stack[top+1]==0)&&(stack[top+2]==0)&&(stack[top+3]==1)) {top=top+num[i];printf("U");} else if((num[i]==4)&&(stack[top+1]==0)&&(stack[top+2]==0)&&(stack[top+3]==0)&&(stack[top+4]==1)) {top=top+num[i];printf("V");} else if((num[i]==3)&&(stack[top+1]==0)&&(stack[top+2]==1)&&(stack[top+3]==1)) {top=top+num[i];printf("W");} else if((num[i]==4)&&(stack[top+1]==1)&&(stack[top+2]==0)&&(stack[top+3]==0)&&(stack[top+4]==1)) {top=top+num[i];printf("X");} else if((num[i]==4)&&(stack[top+1]==1)&&(stack[top+2]==0)&&(stack[top+3]==1)&&(stack[top+4]==1)) {top=top+num[i];printf("Y");} else if((num[i]==4)&&(stack[top+1]==1)&&(stack[top+2]==1)&&(stack[top+3]==0)&&(stack[top+4]==0)) {top=top+num[i];printf("Z");} else if((num[i]==4)&&(stack[top+1]==0)&&(stack[top+2]==0)&&(stack[top+3]==1)&&(stack[top+4]==1)) {top=top+num[i];printf("_");} else if((num[i]==4)&&(stack[top+1]==0)&&(stack[top+2]==1)&&(stack[top+3]==0)&&(stack[top+4]==1)) {top=top+num[i];printf(",");} else if((num[i]==4)&&(stack[top+1]==1)&&(stack[top+2]==1)&&(stack[top+3]==1)&&(stack[top+4]==0)) {top=top+num[i];printf(".");} else if((num[i]==4)&&(stack[top+1]==1)&&(stack[top+2]==1)&&(stack[top+3]==1)&&(stack[top+4]==1)) {top=top+num[i];printf("?");} printf("\n"); return 0;} int main() {int i,n; scanf("%d",&n); for(i=1;i<=n;i++) work(i); return 0;} Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator