hdu 1022 栈

久违的ac,真是艰难。第一次提交的竟然是直接判断b字符串是否为a的倒序。 #include<iostream> #include<stack> #include<string> using namespace std; int main() { int t; string a,b; while(cin>>t>>a>>b) { stack<char>s; string p; int i=0; t=a.size(); while(t--) { s.push(a[a.size()-t-1]); p+="in\n";//cout<<s.top()<<" "<<b[i]; while(!s.empty()&&s.top()==b[i]) { //cout<<"i"<<i<<endl; s.pop(); p+="out\n"; i++; //cout<<s.size()<<"!!"<<endl; } } if(s.size()==0) cout<<"Yes."<<endl<<p; else cout<<"No."<<endl; cout<<"FINISH"<<endl; } return 0; }

SuCicada

hdu 1062(倒置句中单词)<未戳破的玄学>

pe诅咒,多人见证的玄学,终有一天能破解 初回进阶版 #include<stdio.h> #include<string.h> int main() { int T,i,j,t; char a[1000];//="123 4567"; while(scanf("%d",&T)==1) { while(T--) { getchar(); //setbuf(stdin,NULL);//失败了,暂不知为什么 scanf("%[^\n]",a); i=0;////j是大移动位,i是执行位 //xprintf("origin %s\n"); for(j=0;j<strlen(a);j++) { //printf("!!%s\n",a); if(a[j+1]==' '||a[j+1]=='\0') { //printf("a[] %c\n",a[j]); t=i; for(;i<(j+t+1)/2;i++) { a[i]+=a[j-i+t]; a[j-i+t]=a[i]-a[j-i+t]; a[i]=a[i]-a[j-i+t]; //printf("!%s\n",a); } i=j+2; } } printf("%s\n",a); } //printf("end\n"); } } 临终版 #include<stdio.h> #include<string.h> int main() { int T,i,j,t; char a[1003]; scanf("%d",&T); while(T--) { getchar(); scanf("%[^\n]",a); i=0; for(j=0;j<strlen(a);j++) { if(a[j+1]==' '||(j+1)==strlen(a))) { t=j; while(t>=i) printf("%c",a[t--]); if(a[j+1]==' ') printf(" "); i=j+2; } } printf("\n"); } return 0; }

SuCicada

hdu1002(超超长数字相加)

差点gg,用的是字符串数组来存数,加数,下面是原题 *保留了所有的注释 *没有进行代码缩减 Input The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000. Output For each test case, you should output two lines....

SuCicada