您好,登錄后才能下訂單哦!
本文小編為大家詳細介紹“C語言怎么實現成績排名”,內容詳細,步驟清晰,細節處理妥當,希望這篇“C語言怎么實現成績排名”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學習新知識吧。
#include<iostream> #include<stack> using 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<<count; system("pause"); return 0; }
#include<iostream> #include<stack> using namespace std; int main() { string str; cin>>str; int sum=0; bool start =true; for(int i=0;i<str.length();i++){ sum+=(str[i]-'0'); } stack<int> 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; }
//左邊a的個數*中間=右邊 #include<iostream> using 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<c.length();i++){ if(c[i]=='P'||c[i]=='A'||c[i]=='T'){ if(judge==0&&c[i]=='A')count1++; else if(judge==0&&c[i]=='P')judge=1; else if(judge==1&&c[i]=='A')count2++; else if(judge==1&&c[i]=='T')judge=2; else if(judge==2&&c[i]=='A')count3++; else result=false; } else{ result=false; break; } } if(judge!=2||count1*count2!=count3||count2==0)result=false; if(result)cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
#include<iostream> using 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<n;i++){ cin>>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<n;i++){ if(stu[i].score>max.score)max=stu[i]; if(stu[i].score<min.score)min=stu[i]; } cout<<max.name<<" "<<max.num<<endl; cout<<min.name<<" "<<min.num<<endl; return 0; }
#include<iostream> using namespace std; int main() { int n; int num[101]={0}; cin>>n; for(int i=0;i<n;i++){ int tmp; cin>>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<<" "<<i; } else{ flag=0; cout<<i; } } } return 0; }
#include<iostream> using 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<c;i++){ cout<<i+1; } return 0; }
#include<iostream> #include<vector> #include<math.h> using namespace std; int main() { int n,i,j; cin>>n; int count=0; vector<int> 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<prime.size();i++) if(prime[i]-prime[i-1]==2)count++; cout<<count; return 0; }
#include<iostream> using 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<m;i++){ cin>>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<m;i++){ if(count==1){ cout<<a[i]; count=0; } else{ count=0; cout<<" "<<a[i]; } } }
#include<iostream> using 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<<str[j]; } return 0; }
#include<iostream> using 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<i;j++){ if(j!=0){ cout<<" "; } cout<<a[j]; } if(i<1)cout<<"0 0";//注意“零多項式”的指數和系數都是 0,但是表示為0 0. return 0; }
#include<iostream> using 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 #"<<i<<": true"<<endl; else cout<<"Case #"<<i<<": false"<<endl; } return 0; }
#include<iostream> #include<stdio.h> using 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<n;i++){ cin>>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<<sum1<<" "; if(count2==0)cout<<"N "; else cout<<sum2<<" "; if(count1==0)cout<<"N "; else cout<<count1<<" "; if(count3==0)cout<<"N "; else printf("%.1lf ",sum3/count3); if(max==0)cout<<"N"; else cout<<max; return 0; }
#include<iostream> #include<cmath> 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<<a[i]; else cout<<" "<<a[i]; if(count==0)cout<<endl; } return 0; }
#include<iostream> #include<string> #include<cstdio> using namespace std; int main() { string s1,s2,s3,s4; cin>>s1>>s2>>s3>>s4; int len1=s1.length()<s1.length()?s1.length():s2.length(); int len2=s3.length()<s4.length()?s3.length():s4.length(); char weekday,hour; int minute,flag=0; for(int i=0;i<len1;i++){ if(s1[i]==s2[i]&&flag==0&&(s1[i]>='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<len2;i++){ if(s3[i]==s4[i]&&isalpha(s3[i])){ minute=i; break; } } if(hour>='0'&&hour<='9'){ cout<<'0'<<hour; }else{ cout<<hour-'A'+10; } printf(":%02d", minute); return 0; }
讀到這里,這篇“C語言怎么實現成績排名”文章已經介紹完畢,想要掌握這篇文章的知識點還需要大家自己動手實踐使用過才能領會,如果想了解更多相關內容的文章,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。