第三天!!!最近要开始归纳总结Python学习啦!!
1006 换个格式输出整数 (15 分)
让我们用字母
B
来表示“百”、字母S
表示“十”,用12...n
来表示不为零的个位数字n
(<10),换个格式来输出任一个不超过 3 位的正整数。例如234
应该被输出为BBSSS1234
,因为它有 2 个“百”、3 个“十”、以及个位的 4。
输入格式:
每个测试输入包含 1 个测试用例,给出正整数 n(<1000)。
输出格式:
每个测试用例的输出占一行,用规定的格式输出 n。
输入样例 1:
234
输出样例 1:
BBSSS1234
输入样例 2:
23
输出样例 2:
SS123
解题分析及代码:
今天的题目不是很难,这题考查的是如何求数的各个位,要熟练用%运算与/运算。
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
int n,b=0,s=0,g=0;
cin >> n;
b=n/100;
s=n/10%10;
g=n%10;
for(int i=0;i<b;i++) cout << "B" ;
for(int i=0;i<s;i++) cout << "S";
for(int i=1;i<g+1;i++)cout << i;
cout << endl;
return 0;
}
1007 素数对猜想 (20 分)
让我们定义(d_n为:d_n=p_{n+1}-p_n),其中(p_i)是第i个素数。显然有(d_1=1),且对于(n>1)有(d_n)是偶数。“素数对猜想”认为“存在无穷多对相邻且差为2的素数”。
现给定任意正整数
N
(<105),请计算不超过N
的满足猜想的素数对的个数。
输入格式:
输入在一行给出正整数
N
。
输出格式:
在一行中输出不超过
N
的满足猜想的素数对的个数。
输入样例:
20
输出样例:
4
解题分析及代码:
本题对素数如何判断是算法题常考的基础,务必掌握其函数。特别地,在函数体中,我定义了m来存sqrt(n),这样做的目的是,在for循环判断条件中不必一遍遍重复调用sqrt函数计算提高效率,另外若次数过多时,还有可能会造成超时的情况(曾经做过一题就是这种情况,大家需要注意!!)。
#include <iostream> #include <cstring> #include <algorithm> #include <cstdio> #include <cmath> using namespace std; int IsPrime(int n){ int m=sqrt(n); for(int i=2;i<=m;i++) if(n%i==0) return 0; return 1; } int main() { int n; int ans=0; cin >> n; for(int i=n;i-2>1;i--){ if(IsPrime(i)&&IsPrime(i-2)) ans++; } cout << ans << endl; return 0; }
female viagra real viagra online discount how to buy cheap viagra online
what is cephalexin 500 mg cephalexin 250 mg bactrim vs keflex acid reflux
cephalexin take with food keflex 500 mg can cephalexin be used for bladder infection
keflex reactions cephalexin birth control keflex and tooth infection
generic cephalexin cephalexin tylenol cephalexin and penicillin together
amoxicillin dosage for kids does amoxicillin treat bronchitis is amoxicillin addictive
does amoxicillin treat std amoxicillin là thuốc gì adult dose of amoxicillin
dark urine when taking augmentin augmentin wechselwirkung pille allergies to augmentin in children
does amoxicillin affect birth control pills fish amoxicillin 500mg when does amoxicillin start working for strep
is dog amoxicillin the same as human amoxicillin pediatric amoxicillin dosage chart amoxicillin-pot clavulanate 875-125 mg oral tablet
ciprofloxacin for uti dosage side effects ciprofloxacin ciprofloxacin-hydrocortisone ear drops price
is ciprofloxacin and ofloxacin the same ciprofloxacin and pantoprazole ciprofloxacin tablet uses
how long after taking doxycycline can i drink alcohol doxycycline rash how long does it take for doxycycline to work for bv
prednisone 50 mg para que sirve over the counter prednisone for humans can prednisone kill you
why is my prednisone not working prednisone for plantar fasciitis dosage of prednisone for sinus infection
cephalexin antibiotics for dogs cephalexin 500mg for ear infection is cephalexin for dogs the same as for humans
pharmacy viagra canada viagra mastercard online pharmacy where can i get viagra in south africa
viagra singapore prescription buy cheap viagra online canada sildenafil tablets 120 mg
buy tadalafil cheap pictures of cialis cialis mg
order viagra online usa can i buy female viagra over the counter viagra 100 pill
how to use cialis buy cialis cheap cheap online tadalafil
viagra 20mg generic best sildenafil brand cost of sildenafil in mexico
college admission essay service common application essay help admission essay writing services
whats a hook in an essay custom essays writing best custom essay website
argument essay examples professional essay writing services essay sentence starters
professional college essay writers need help writing essay custom law essay
what is a literary analysis essay good essay writing services problem solution essay topics
cialis mail order pharmacy cheap pharmacy cialis clarithromycin online pharmacy
alpesh pharmacy store charlotte nc online pharmacy no prescription flagyl target pharmacy fluoxetine
codeine nz pharmacy cheapest pharmacy to get concerta tadacip online pharmacy
target pharmacy nexium propecia pharmacy cost global pharmacy
best online pharmacy no prescription publix pharmacy doxycycline gold pharmacy online
reliable rx pharmacy coupon costa rica pharmacy viagra robaxin online pharmacy
tadalafil 25 mg how many years can you take tadalafil vidalista tadalafil 60 mg
tadalafil plus sildenafil tadalafil or sildenafil which is better how does tadalafil work
tadalafil in stores tadalafil price cvs tadalafil and working out
tadalafil pills tadalafil discount card tadalafil 10 mg para que sirve
tadalafil 10mg daily can you buy tadalafil over the counter tadalafil buy online canada
tadalafil other names what happens if you take 2 tadalafil what happens if a woman takes tadalafil
tadalafil vs sildenafil vs vardenafil can you drink beer with tadalafil tadalafil costs
does tadalafil lower your blood pressure dental side effect of tadalafil how long does it take for tadalafil to kick in
tadalafil for erectile dysfunction tadalafil how taken tadalafil vs tamsulosin
goodrx tadalafil 5mg sildenafil tadalafil or vardenafil tadalafil para que sirve mujeres
tadalafil en ligne tadalafil para que serve what if tadalafil doesn’t work
“40mg tadalafil” taken tadalafil 50 mg cialis does tadalafil keep you hard after coming?
buy tadalafil 10mg tadalafil otc grapefruit tadalafil
can you drink alcohol with tadalafil tadalafil 60 mg reviews tadalafil 5mg uses
canadian tadalafil is 20mg of tadalafil too much? tadalafil forum
should i take tadalafil with food sunrise tadalafil can sildenafil and tadalafil be taken together
tadalafil online uk tadalafil 5mg tablets tadalafil refractory period
can tadalafil be taken with alcohol tadalafil. cialis tadalafil online