A
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
int x;
scanf ("%d",&x);
if (x<=100000) printf ("%.0f\n",x*0.1);
else if (x<=200000) printf ("%.0f\n",100000*0.1+(x-100000)*0.075);
else if (x<=400000){
printf ("%.0f\n",17500+(x-200000)*0.05);
}
else if (x<=600000) {
printf ("%.0f",27500+(x-400000)*0.03);
}
else if (x<=1000000){
printf ("%.0f",33500+(x-600000)*0.015);
}
else printf ("%.0f",39500+(x-1000000)*0.01);
return 0;
}
b
c语言
#include <stdio.h>
#include <string.h>
int main()
{
char s[10010];
gets(s);
int a,b,c,d;
a=b=c=d=0;
for (int i=0;i<strlen(s);i++){
if ((s[i]>='a'&&s[i]<='z')||(s[i]>='A'&&s[i]<='Z')){
a++;
}
else if (s[i]>='0'&&s[i]<='9') b++;
else if (s[i]==' ') c++;
else d++;
}
printf ("%d %d %d %d\n",a,b,c,d);
return 0;
}
c++
//b题使用fgets过不了 string存字符串
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <cstdio>
using namespace std;
int main()
{
char s[100010];
//fgets(s,330,stdin);//gets有安全问题 现在不少oj不能用了建议用fgets
//用fgets能整行读入
string s;
getline(cin,s);//string 的整行读入
int a,b,c,d;
a=b=c=d=0;
//for (int i=0;i<strlen(s);i++){
for (int i=0;i<s.size();i++){
if ((s[i]>='a'&&s[i]<='z')||(s[i]>='A'&&s[i]<='Z')){
a++;
}
else if (s[i]>='0'&&s[i]<='9') b++;
else if (s[i]==' ') c++;
else d++;
}
printf ("%d %d %d %d\n",a,b,c,d);
return 0;
}
C
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string.h>
using namespace std;
int main()
{
long long ans=0;
long long p=0;
int n;
scanf ("%d",&n);
for (int i=1;i<=n;i++){
p=p*10+2;
ans+=p;
}
printf ("%lld",ans);
return 0;
}
D
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <cstdio>
using namespace std;
int main()
{
long long p=1;
int n;
long long sum=0;
scanf("%d", &n);
for (int i = 1; i <= n; i ++ ){
p*=i;
sum+=p;
}
printf ("%lld",sum);
return 0;
}
更大数据范围使用高精度
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <vector>
using namespace std;
vector <int> add(vector <int> &a,vector <int> &b){
if (a.size()<b.size()) return add(b,a);
vector <int> s;
int t=0;
for (int i=0;i<a.size();i++){
t+=a[i];
if (i<b.size()) t+=b[i];
s.push_back(t%10);
t/=10;
}
if (t) s.push_back(1);
return s;
}
vector <int> mul(vector <int> &a,int b){
vector <int> m;
int t=0;
for (int i=0;i<a.size()||t>0;i++){
if (i<a.size()) t+=a[i]*b;
m.push_back(t%10);
t/=10;
}
while (m.size()>1&&m.back()==0) m.pop_back();
return m;
}
int main()
{
vector <int> a,b,c;
int n;
scanf("%d", &n);
a.push_back(1);
b.push_back(1);
for (int i=2;i<=n;i++){
b=mul(b,i);
a=add(a,b);
}
for (int i=a.size()-1;i>=0;i--) printf ("%d",a[i]);
return 0;
}
E
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <vector>
using namespace std;
int main()
{
int a,b,c;
scanf ("%d%d%d",&a,&b,&c);
double ans=0.0;
for (int i=1;i<=a;i++) ans+=i;
for (int i=1;i<=b;i++) ans+=pow(i,2);
for (double i=1.0;i<=c;i++) ans+=1.0/i;
printf ("%.2f",ans);
return 0;
}
F
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;
int main (){
int n;
scanf ("%d",&n);
long long ans=1;
for (int i=1;i<n;i++){
ans=(ans+1)*2;
}
printf ("%lld\n",ans);
return 0;
}
G
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <vector>
using namespace std;
int main()
{
double x;
scanf ("%lf",&x);
double a[100010];
a[0]=1.0;
a[1]=(x/a[0]+a[0])/2.0;
int cnt=1;
while (fabs(x-a[cnt]*a[cnt])>1e-7){
cnt++;
a[cnt]=(x/a[cnt-1]+a[cnt-1])/2.0;
}
printf ("%.3lf",a[cnt-1]);
return 0;
}
//浮点数二分了解一下
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <vector>
using namespace std;
int main()
{
double x;
scanf ("%lf",&x);
double l=-1e5,r=1e5;
while (r-l>1e-9){
double mid=(l+r)/2.0;
if (mid*mid<x) l=mid;
else r=mid;
}
printf ("%.3f",l);
return 0;
}
H
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <vector>
using namespace std;
int main()
{
int n;
scanf("%d", &n);
for (int i=2;i<=n;i++){
int p=1;
for (int j=2;j<=i/j;j++){
if (i%j==0) {
p=0;
break;
}
}
if (p) printf ("%d\n",i);
}
return 0;
}
I
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[100010];
int main (){
int n;
//scanf ("%d",&n);
n=10;
for (int i = 1; i <= n; i ++ ){
scanf ("%d",&a[i]);
}
for (int i=1;i<=n;i++){
int ms=a[i];
for (int j=i+1;j<=n;j++){
if (a[j]<ms){
int t=ms;
ms=a[j];
a[j]=t;
}
}
a[i]=ms;
}
for (int i = 1; i <= n; i ++ ) printf ("%d ",a[i]);
return 0;
}
J
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;
int main (){
int a[3][3];
int n=3;
int x,y;
x=y=0;
for (int i=0;i<n;i++){
for (int j=0;j<n;j++){
scanf ("%d",&a[i][j]);
if (i==j) x+=a[i][j];
if (i+j==2) y+=a[i][j];
}
}
printf ("%d %d\n",x,y);
return 0;
}