文章目次
复数乘法
题目形貌:
输入两个表现复数的字符串,输出它们相乘的效果的字符串
复数字符串用a+bi表现(a, b 为整数, i为虚数单位,i2=1)
输入例子:
1±2i
3+4i
输出例子:
11±2i
例子分析:
(1±2i)(3+4i) = (3 + 4i - 6i - 8i * i) = 11±2i
[code]#include#include#includeusing namespace std;int strToInt(string& str){ int ret = 0; int flag = 1; for(auto& ch : str) { if(ch == '-') flag = -1; if(ch >= '0' && ch > str1 >> str2; string sr1 = str1.substr(0, str1.find('+')); string sf1 = str1.substr(str1.find('+')+1); string sr2 = str2.substr(0, str2.find('+')); string sf2 = str2.substr(str2.find('+')+1); int srInt1 = strToInt(sr1); int sfInt1 = strToInt(sf1); int srInt2 = strToInt(sr2); int sfInt2 = strToInt(sf2); int sr = srInt1 * srInt2 - sfInt1 * sfInt2; int sf = srInt1 * sfInt2 + sfInt1 * srInt2; cout 5
当 k = 2 时,应当返回: 2->1->4->3->5
当 k = 3 时,应当返回: 3->2->1->4->5
输入形貌:
第一行:依次输入链表中的各个元素,以"#“竣事
第二行:每组数量k
输出形貌:
处理惩罚后的链表中的各个元素,以”->"毗连</p> [code]#include #include #include using namespace std;void reverseStr(vector& sv, int start, int end){ while(start < end) sv[start++].swap(sv[end--]);}int main(){ string s; vector sv; while(cin >> s) { if(s != "#") sv.push_back(s); else break; } int k; int start = 0; cin >> k; while(sv.size() - start >= k) { reverseStr(sv, start, start + k - 1); start += k; } for(int i = 0; i < sv.size() - 1; i++) { cout |