B2005 字符三角形
题意:
给出一个字符,打印出一个底5个字符,高3个字符的三角形
思路:
1.用一个字符类型的变量储存输入的字符
2.输出变量## 题意:
如图所示:
| c | ||||
|---|---|---|---|---|
| c | c | c | ||
| c | c | c | c | c |
AC代码
#include<bits/stdc++.h>
using namespace std;
char c;
int main(){
cin >> c;
cout << " "<< " "<< c<< endl;
cout << " "<< c<< c<< c<< endl;
cout << c<< c<< c<< c<< c<< endl;
return 0;
}错因:
以为要换行,但是实际上不用换行
P1424 小鱼的航程(改进版)
题意:
小鱼每一天都游泳250km(除了周六,周日),他从第周x开始游泳,经过n天,小鱼游了多远
思路:
1.循环n次,每次先判断x是不是周六和周天,不是的话sum加上250
2.将x调整到下一天,如果x是8,就改为1
3.输出结果
AC代码
#include<bits/stdc++.h>
using namespace std;
int x, n;
long long sum;
int main(){
cin >> x>> n;
while(n--){
if(x != 6 && x != 7){
sum += 250;
}
x++;
if(x == 8){
x = 1;
}
}
cout << sum;
return 0;
}错因:
第一次没有加高天数
P2640 神秘磁石
题意:
有两个磁石,当他们的坐标都是素数时,破坏力最大,如果距离为k,破坏力将达到顶峰,问:坐标应是多少,破坏力将达到顶峰?
思路:
1.枚举2到n的所有质数,存到一个数组里
2.双重循环左右端点,只要差距等于k,就输出左右端点,并结束循环
AC代码
#include<bits/stdc++.h>
using namespace std;
bool f(int n){
if(n < 2){
return false;
}
for(int i = 2;i * i <= n;i++){
if(n % i == 0){
return false;
}
}
return true;
}
int n, k;
int a[10010];
int main(){
cin >> n>> k;
int l = 0;
for(int i = 2;i <= n;i++){
if(f(i) == true){
l++;
a[l] = i;
}
}
int sum = 0;
for(int i = 1;i <= l;i++){
for(int j = 1;j <= l;j++){
if(a[j] - a[i] == k){
cout << a[i]<< " "<< a[j]<< endl;
sum++;
break;
}
}
}
if(sum == 0){
cout << "empty";
}
return 0;
}
错因:
没时间修改代码