建站快车代理商,网站顶部滑动展示的div层提示效果,西宁网站建设的公司,北京现在可以自由出入吗忙碌了一周#xff0c;一直没时间更新#xff0c;趁着周末来更新第二个题目。
题目 题目解析
这个题目相比于上一个题目来说#xff0c;会简单一些#xff0c;不涉及到那些复杂的算法#xff0c;就是对于字符串的处理。
算法步骤
输入一个字符串根据分号#xff0c;将…忙碌了一周一直没时间更新趁着周末来更新第二个题目。
题目 题目解析
这个题目相比于上一个题目来说会简单一些不涉及到那些复杂的算法就是对于字符串的处理。
算法步骤
输入一个字符串根据分号将字符串拆成子字符串利用数组进行保存。分情况讨论字母后面的数字是两位数和字母后面的数字是一位数两种情况再根据每个子字符串首位的字符决定x和y坐标的移动。
源代码
#include iostream
#include string
#include vector
using namespace std;int main() {string s;cin s;int len s.size(); // 输入字符串vectorstring strs;int x 0, y 0; // 设置初始坐标int sublen 0;for (int i 0; i len; i) {if (s[i] ! ;) {sublen;continue;} else {string substrs s.substr(i - sublen, sublen); // 截取子字符串strs.push_back(substrs); // 将子字符串存入数组sublen 0;} }for (int i 0; i strs.size(); i) { // 对于每个子字符串分情况讨论int num 0;if ((strs[i].size() 3) (strs[i][1] 0) (strs[i][1] 9) (strs[i][2] 0) (strs[i][2] 9)) {num (strs[i][1] - 0) * 10 (strs[i][2] - 0);}if ((strs[i].size() 2) (strs[i][1] 0) (strs[i][1] 9)) {num strs[i][1] - 0;} switch (strs[i][0]) { // 对坐标x,y进行计算case A: x - num;break;case D: x num;break;case S: y - num;break;case W: y num;break;default:break;}}cout x , y endl; // 输出结果
}参考代码