蓝桥2014题库难点汇总

入门训练

 
1 #include<iostream>
2 using namespace std;
3 int main()
4 {
5 int a,b;
6 cin>>a>>b;
7 cout<<a+b;
8 return 0;
9 }
难点:若用C++注意别漏 using namespace std;
1 #include <stdio.h> 
2 int main()
3 {
4     unsigned long long n;
5     scanf("%I64u", &n);
6     printf("%I64u
", n*(n+1)/2);
7     return 0;
8 }
难点:注意64位用法
 1 #include <stdio.h>
 2  
 3 int main()
 4 {
 5     long long n, sum;
 6     scanf("%I64d", &n);
 7     sum = (n + 1) * n / 2;
 8     printf("%I64d", sum);
 9     return 0;
10 }
难点:注意64位用法
 1 #include <stdio.h>
 2 #include <math.h>
 3  
 4 int main()
 5 {
 6     int r;
 7     scanf("%d", &r);
 8     printf("%.7lf
", atan(1.0)*4*r*r);
 9     return 0;
10 }
难点: 1.注意输出要求的长度 .7 2.注意PI的计算 atan(1.0)*4
Fibonacci数列
 1 #include <stdio.h>
 2 int fun(int x)
 3 {
 4     if(x==1||x==2)  //注意递归的结束
 5       return 1;
 6     else
 7       return fun(x-1)+fun(x-2);
 8 }
 9 int main()
10 {
11    int n,i;
12    scanf("%d",&n);
13    printf("%d",fun(n)%10007);
14    return 0;
15 }
难点:递归的使用

基础练习

时间转换
1
#include<iostream> 2 using namespace std; 3 int main() 4 { 5 int t; 6 cin>>t; 7 int h,m,s; 8 h=t/3600; 9 m=t%3600/60; 10 s=t%3600%60; 11 cout<<h<<":"<<m<<":"<<s<<endl; 12 return 0; 13 }
字符串小写转大写
#include <ctype.h> http://baike.baidu.com/link?url=WH94T6MdbBKwTAqcoGmMz4neQkY7m1odU14d1TxTDm3fHEyhJeGtvJJ9GyX9ZWn3JsfYW1m8Aavez0zfETYjx_
1
for(i = 0; i < sizeof(s); i++) 2 s[i] = toupper(s[i]);
矩阵相交面积计算,方法不错
1
#include <iostream> 2 #include <algorithm> //用来使用max min 3 #include <cmath> 4 #include <cstdio> 5 using namespace std; 6 int main() 7 { 8 double x1, x2, y1, y2; 9 double q1, q2, w1, w2; 10 while (cin >> x1 >> y1 >> x2 >> y2 >> q1 >> w1 >> q2 >> w2) 11 { 12 double xx = max(min(x1, x2), min(q1, q2)); 13 double yy = max(min(y1, y2), min(w1, w2)); 14 double xxup = min(max(x1, x2), max(q1, q2)); 15 double yyup = min(max(y1, y2), max(w1, w2)); 16 if (xxup > xx) 17 printf("%.2f ", fabs((xx)-(xxup))*fabs((yy)-(yyup))); 18 else printf("0.00 "); //别忘了不想交的时候输出0 19 } 20 }
 
 
原文地址:https://www.cnblogs.com/wwjyt/p/3608904.html