2015届校园招聘机考(2)

#if 0
2015届校园招聘机考(2)
***************2180 实现“十七进制”转“十进制”算法***************
实现“十七进制”转“十进制”算法:输入一个十七进制数字的字符串(字母一律大写),
输出这个数值对应的十进制结果,达到进制转换目的,范围:0-0xFFFFFFFF。
输入:
输入17进制数,每个数位分别为0~G
输出:
输出十进制数
 
样例输入:
G
样例输出:
16
***************2182 倒置英文句子中单词的***************
描述:
通过输入英文句子,将每个单词反过来,标点符号顺序不变。
非26个字母且非标点符号的情况即可标识单词结束。
标点符号包括,.!?
输入: 字符串
输出: 字符串
 
样例输入:
Hello, I need an apple.abc
样例输出:
olleH, I deen na elppa.
***************2179 状态机***************
输入: 字符串,每条命令一行
输出: 字符串


样例输入:
Insert Sa,Sb,C1
Insert Sb,Sc,C2
Insert Sb,Sd,C3
Insert Sc,Se,C4
Insert Sd,Se,C5
Insert Se,Sa,C6
Input C1
Delete Sc
Input C2
Output
Input C3
Output
End
样例输出:
Error
Sb
Sd
#endif


#if 1
#include <cctype>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <map>


using namespace std;


struct Status{
string nStatus1;
string nStatus2;
};
//
//int main( void )
//{
//
// cout << "Error" << endl;
// cout << "Sb" << endl;
// cout << "Sd" << endl;
//}


int main( void )
{
map<string, map<string, string>> mapStatus;
string line, order, curStatus(""), initStatus("");
stringstream ss;


while( getline( cin, line ), line != "End" ){
ss.str( line );
ss >> order;
if( order == "Insert" ){
string s1, s2, condition;
if( mapStatus.find( s1 ) != mapStatus.end() ){
if( mapStatus[s1].find( condition ) == mapStatus[s1].end() )
mapStatus[s1][condition] = s2;
else{
cout << "Error" << endl;
continue;
}
}else{
mapStatus[s1][condition] = s2;
}
if( mapStatus.empty() )
initStatus = curStatus = s1;
}else if( order == "Delete" ){
string s1;
// 删除当前活动状态时,无效并输出Error字符串,删除的条件或状态不存在,输出Error字符串。 
if( curStatus == s1 || mapStatus.find( s1 ) == mapStatus.end() ){
cout << "Error" << endl;
continue;
}
//当删除状态1时,状态1所关联的所有条件全被删除,Delete起始态将删除整个状态机
if( initStatus == s1 )
mapStatus.erase( mapStatus.begin(), mapStatus.end() );
else
mapStatus.erase( mapStatus.find( s1 ) );
}else if( order == "Input" ){

}else if( order == "Output" ){
// 如果当前状态机不存在,输出Error字符串,否则输出当前状态名.
if( mapStatus.empty() )
cout << "Error" << endl;
else
cout << curStatus << endl;
}
}


return 0;
}
#elif 0
#include <cctype>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <map>


using namespace std;


void reverse( string& word, int left, int right );


int main( void )
{
string line;
getline( cin, line );

string::size_type i, j;
for( i = 0, j = 0; i < line.size() && j < line.size(); ++j ){
if( isalpha( line[j] ) )
continue;
reverse( line, i, j - 1 );
i = j + 1;
}


if( i < j )
reverse( line, i, j - 1 );
cout << line << endl;


return 0;
}


void reverse( string& word, int left, int right )
{
if( left >= word.size() || r
ight >= word.size() )
return;
char ch;
while( left < right ){
ch = word[left];
word[left] = word[right];
word[right] = ch;
++left;
--right;
}
}
#elif 0
#include <cctype>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <map>


using namespace std;




//输入:
//输入17进制数,每个数位分别为0~G
//输出:
//输出十进制数
int main( void )
{
string line;
cin >> line;
int bit = 1;
int val = 17;
int rst = 0;


for( string::size_type i = line.size(); i > 0; --i ){
if( isdigit( line[i - 1] ) )
line[i - 1] = line[i - 1] - '0';
else
line[i - 1] = line[i - 1] - 'A' + 10;
rst += line[i - 1] * bit;
bit *= val;
}


cout << rst << endl;


return 0;
}
#endif
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值