C语言编程PAT乙级学习笔记示例分享
目录
- 1001 害死人不偿命的(3n+1)猜想
- 1002 写出这个数
- 1003 我要通过!
- 1004 成绩排名
- 1005 继续(3n+1)猜想
- 1006 换个格式输出整数
- 1007 素数对猜想问题
- 1008 数组元素循环右移问题
- 1009 说反话
- 1010 一元多项式求导
- 1011 A+B 和 C
- 1012 数字分类
- 1013 数素数
- 1014 福尔摩斯的约会
1001 害死人不偿命的(3n+1)猜想
#include#includeusing namespace std; int main(){ int n,count=0; cin>>n; while(n!=1){if(n%2==0)n=n/2; else n=(3*n+1)/2; count++; } cout<
1002 写出这个数#include#includeusing namespace std; int main(){ string str; cin>>str; int sum=0; bool start =true; for(int i=0; i sta; while(sum!=0){sta.push(sum%10); sum=sum/10; } while(!sta.empty()){if(start)start=false; else cout<<" "; int tmp=sta.top(); sta.pop(); switch(tmp){case 0:cout<<"ling"; break; case 1:cout<<"yi"; break; case 2:cout<<"er"; break; case 3:cout<<"san"; break; case 4:cout<<"si"; break; case 5:cout<<"wu"; break; case 6:cout<<"liu"; break; case 7:cout<<"qi"; break; case 8:cout<<"ba"; break; case 9:cout<<"jiu"; break; } } system("pause"); return 0; }
1003 我要通过!//左边a的个数*中间=右边#includeusing namespace std; int main(){ int n; cin>>n; while(n--){string c; cin>>c; int count1=0,count2=0,count3=0,judge=0; bool result=true; for(int i=0; i
1004 成绩排名#includeusing namespace std; typedef struct student{ string name; string num; int score; }Student; int main(){ int n; cin>>n; struct student stu[n]; for(int i=0; i >stu[i].name; cin>>stu[i].num; cin>>stu[i].score; } struct student min=stu[0]; struct student max=stu[0]; for(int i=1; i max.score)max=stu[i]; if(stu[i].score
1005 继续(3n+1)猜想#includeusing namespace std; int main(){ int n; int num[101]={0}; cin>>n; for(int i=0; i >tmp; num[tmp]=1; } for(int i=0; i<101; i++){if(num[i]==1){int temp=i; while(temp>1){if(temp%2==0)temp/=2; else temp=(3*temp+1)/2; if(temp!=1&&temp<101)num[temp]=0; }} } int flag=1; for(int i=100; i>=0; i--){if(num[i]==1){if(flag==0){cout<<" "<
1006 换个格式输出整数#includeusing namespace std; int main(){ int n; cin>>n; int a,b,c; a=n/100; b=n%100/10; c=n%10; while(a!=0){cout<<"B"; a--; } while(b!=0){cout<<"S"; b--; } for(int i=0; i
1007 素数对猜想问题#include#include #include using namespace std; int main(){ int n,i,j; cin>>n; int count=0; vector prime; for(int i=2; i<=n; i++){for(j=2; j<=sqrt(i); j++){if(i%j==0)break; }if(j>sqrt(i))prime.push_back(i); } for(int i=1; i
1008 数组元素循环右移问题#includeusing namespace std; //change函数void change(int a[],int l,int r){ for(int i=l; i<=(l+r)/2; i++){int tmp=a[i]; a[i]=a[l+r-i]; a[l+r-i]=tmp; }}int main(){ int m,n; cin>>m>>n; n%=m; //考虑当需要循环的次数超过了数列总数时的情况!!! int a[m]={0}; for(int i=0; i >a[i]; } change(a,0,m-1-n); change(a,m-n,m-1); change(a,0,m-1); int count=1; for(int i=0; i 1009 说反话 #includeusing namespace std; int main(){string str[80]; int i=0,j; while(cin>>str[i]){//这个会经常使用,要记住啊。i++; }for(j=i-1; j>=0; j--){if(j!=i-1)cout<<" "; cout<
1010 一元多项式求导#includeusing namespace std; int main(){ int a[1000]; int i=0; int m,n; while(cin>>m>>n){a[i]=m*n; a[i+1]=n-1; if(a[i]==0&&a[i+1]==-1)continue; else i+=2; }for(int j=0; j 1011 A+B 和 C #includeusing namespace std; int main(){int n; cin>>n; int i=0; while(n--){i++; double a,b,c; //看测试用例,选用double或者float类型cin>>a>>b>>c; if(a+b>c)cout<<"Case #"<
1012 数字分类#include#includeusing namespace std; int main(){int n,i; cin>>n; int a[1001]; int sum1=0,flag=1,sum2=0,count1=0,count2=0,count3=0,max=0; double sum3=0; for(i=0; i >a[i]; if(a[i]%2==0&&a[i]%5==0){sum1+=a[i]; }else if(a[i]%5==1){sum2=sum2+flag*a[i]; flag=flag*(-1); count2++; }else if(a[i]%5==2){count1++; }else if(a[i]%5==3){sum3+=a[i]; count3++; }else if(a[i]%5==4){if(a[i]>max)max=a[i]; }}if(sum1==0)cout<<"N "; else cout<
1013 数素数#include#include using namespace std; bool isprime(int n){int i; if(n==2){return true; }else if(n<=1){return false; }else{for(i=2; i<=sqrt(n); i++){//要用平方根,如果用n/2找素数,会显示一个错误,表示代码运算量过大。if(n%i==0)return false; }if(i>sqrt(n))return true; else return false; }}int main(){int m,n; cin>>m>>n; int a[110000]={0}; int x=1; for(int i=1; i<110000; i++){if(isprime(i)){a[x]=i; x++; }}int count=0; for(int i=m; i<=n; i++){count++; count=count%10; if(count==1)cout<
1014 福尔摩斯的约会#include#include#include using namespace std; int main(){string s1,s2,s3,s4; cin>>s1>>s2>>s3>>s4; int len1=s1.length()='A'&&s1[i]<='G')){weekday=s1[i]; flag=1; switch(weekday){case 'A':cout<<"MON "; break; case 'B':cout<<"TUE "; break; case 'C':cout<<"WED "; break; case 'D':cout<<"THU "; break; case 'E':cout<<"FRI "; break; case 'F':cout<<"SAT "; break; case 'G':cout<<"SUN "; break; }continue; //必不可少,保证下一步的if语句可以执行。不使用continue的话,可以把两个if语句的执行顺序调换一下。}if(s1[i]==s2[i]&&flag==1&&((s1[i]>='A' && s1[i]<='N') || (s1[i] >= '0' && s1[i] <= '9'))){hour=s1[i]; break; }}for(int i=0; i ='0'&&hour<='9'){cout<<'0'<
【C语言编程PAT乙级学习笔记示例分享】以上就是C语言编程PAT乙级学习笔记实现示例的详细内容,更多关于C语言PAT乙级的资料请关注脚本之家其它相关文章!
推荐阅读
- 单细胞论文记录(part9)--Spatial charting of single-cell transcriptomes in tissues
- 高性能|高性能 Jsonpath 框架,Snack3 3.2.29 发布
- 华为防火墙私网用户通过NAT No-PAT访问Internet(无定向server)
- Uncaught InvalidArgumentException: Please provide a valid cache path. in /apps/vendor/laravel/framew
- 华为防火墙私网用户通过NAT No-PAT访问Internet(访问明确的目的Server)
- Java设计模式—适配器模式(adapter pattern)
- XPath|掌握数据采集工具的核心技巧
- Kubernetes——存储卷(empyDirhostPathnfs)
- [kubernetes] 持久化存储之emptyDir/HostPath/NFS
- Unable to select a master clock domain because no path can be found from “SYSTRACE“ to “LINUX_FTRACE