2015年
第一题
代码,不保证正确:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main(){
double x;
cin >> x;
double ans = 1;
double n = 1;
double k = 1;
double temp;
do {
temp = pow(x, n) / k;
ans += temp;
n++;
k = k * n;
} while (fabs(temp) > 1.0e-7);
cout << fixed << setprecision(7) << ans << endl;
return 0;
}
第二题
参考了http://blog.csdn.net/kisslotus/article/details/50759218
这篇博客。
下面给出代码:
#include <iostream>
#include <string>
using namespace std;
void print(string input);
int main(){
string test1 = "1 x 2 y z 3 d h 4 g 5";
string test2 = "3 x 9 0 z k k 1 0 d m h 1 g 8";
print(test1);
cout << endl;
print(test2);
cout << endl;
return 0;
}
void print(string input){
if (input.length() == 0) {