当前位置:首页 > 北京理工大学计算机复试上机题00-12
/*while(!a.empty()) { cout< while(!a.empty()) { } b.push(a.top()); a.pop(); /*while(!b.empty()) { cout< }*/ stack while(!b.empty()) { if(b.top()>='0' && b.top()<='9') { t.push(b.top()-'0'); b.pop(); } else { if(b.top()=='+') { } int c,d; c=t.top(); t.pop(); d=t.top(); t.pop(); t.push(c+d); if(b.top()=='-') { int c,d; c=t.top(); t.pop(); d=t.top(); t.pop(); t.push(d-c); } if(b.top()=='*') } } { int c,d; c=t.top(); t.pop(); d=t.top(); t.pop(); t.push(c*d); } if(b.top()=='/') { int c,d; c=t.top(); t.pop(); d=t.top(); t.pop(); t.push(d/c); } b.pop(); cout< } 2011年上机及答案1 1.输入一组单词(区分大小写),统计首字母相同的单词个数,相同的单词不累加,输出格式“字母,以该字母为首的单词个数。 //输入一组单词(区分大小写),统计首字母相同的单词个数 //相同的单词不累加,输出格式\字母,以该字母为首的单词个数。 #include vector while(cin>>s) str.push_back(s); sort(str.begin(),str.end()); vector char c; while(i count++; i++; s1=str[i]; while(s1[0]==c&&i { } count++; i++; s1=str[i]; cout< } return 0; } 2.输入一组单词,(区分大小写),输出这些单词的字典排序。。。 //输入一组单词(区分大小写),输出这些单词的字典排序 #include string s; while(cin>>s) str.push_back(s); stable_sort(str.begin(),str.end()); int j; for(j=0;j if(str[j][0]>=97) break; vector string c1,c2; while(n c1=str[n]; c2=str[k]; c2[0]=toupper(c2[0]); if(c2[0] str2.push_back(str[k]); k++; } if(c2[0]>c1[0]) { str2.push_back(str[n]); n++; } if(c2[0]==c1[0]) { if(c1<=c2) { str2.push_back(str[n]); str2.push_back(str[k]); n++; k++; } if(c1>c2) { str2.push_back(str[k]); } str2.push_back(str[n]); n++; k++; } } while(n { str2.push_back(str[n]); } n++; while(k str2.push_back(str[k]); k++; { } for(vector
共分享92篇相关文档