1.人与神
#include<bits/stdc++.h>
using namespace std;
int main(){
cout<<"To iterate is human, to recurse divine."<<endl;
return 0;
}
2.计算邮费(卡精度,需要用double)
#include <bits/stdc++.h>
using namespace std;
float a, pri;
int b;
char c;
int main() {
cin >> a >> b >> c;
if (b == 90)
pri = a * 6.95;
if (b == 93)
pri = a * 7.44;
if (b == 97)
pri = a * 7.93;
if (c == 'm')
pri *= 0.95;
if (c == 'e')
pri *= 0.97;
cout << fixed << setprecision(2) << pri;
return 0;
}
3.跟奥巴马一起画方块
#include <bits/stdc++.h>
using namespace std;
int h, l;
char m;
int main() {
cin >> l >> m;
h = (l + 1) / 2;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= l; j++)
cout << m;
cout << endl;
}
return 0;
}
4.输出矩阵两个对角线上的数(二维数组)
#include <bits/stdc++.h>
using namespace std;
int n, a[101][101];
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
cin >> a[i][j];
for (int i = 1; i <= n - 1; i++)
cout << a[i][i] << " ";
cout << a[n][n] << endl;
for (int i = 1; i <= n - 1; i++)
cout << a[n - i + 1][i] << " ";
cout << a[1][n];
return 0;
}
5.输出GPLT
#include <bits/stdc++.h>
using namespace std;
string a;
int l, ng = 0, np = 0, nl = 0, nt = 0, maxx = 0;
int main() {
cin >> a;
l = a.length();
for (int i = 0; i < l; i++) {
if (a[i] == 'G' || a[i] == 'g')
ng++;
else if (a[i] == 'P' || a[i] == 'p')
np++;
else if (a[i] == 'L' || a[i] == 'l')
nl++;
else if (a[i] == 'T' || a[i] == 't')
nt++;
}
maxx = max(ng, np);
maxx = max(maxx, nl);
maxx = max(maxx, nt);
for (int i = 1; i <= maxx; i++) {
if (ng != 0) {
cout << "G";
ng--;
}
if (np != 0) {
cout << "P";
np--;
}
if (nl != 0) {
cout << "L";
nl--;
}
if (nt != 0) {
cout << "T";
nt--;
}
if (ng == 0 && np == 0 && nl == 0 && nt == 0)
break;
}
return 0;
}