PAT乙级练习题

1.

#include 
using namespace std;
int main()
{
    int n;
    cin>>n;
    int sum=0;
    do{
        if(n%2==0)
        {
           n=n/2;
           sum=sum+1 ;
        }
        else if(n%2!=0)
        {
            n=(3*n+1)/2;
            sum=sum+1;
        }
    }while(n!=1);
    cout<

2.

#include 
#include 
#include 
#include 
using namespace std;
int main()
{
    string s;
    cin>>s;
    int sum=0;
    int num=0;
    for(int n=0;s[n]!='\0';n++)
    {
        num=num+1;
    }
    for(int i=0;i0;j--)
    {
        cout<

4.

#include 
#include 
#include 
using namespace std;
int main()
{
    int n;
    cin>>n;
    class Student{
public:
    string name;
    string xuehao;
    int grade;};
    Student S[100];
    for(int i=0;i>S[i].name>>S[i].xuehao>>S[i].grade;
    int max=0;
    for(int i=0;imax)
        max=S[i].grade;}
    int min=100;
    for(int i=0;i

6.

#include 
using namespace std;
int main()
{
    int n;
    cin>>n;
    int ones,tens,hundreds;
    char num[100];
    int len=0;//记录num中元素的个数
    ones=n%10;
    for(int j=ones;j>=1;j--)
    {
        num[len]=j+'0';
        len=len+1;
    }
    n=n/10;
    if(n!=0)
    {
        tens=n%10;
        for(int j=1;j<=tens;j++)
        {
            num[len]='S';
            len=len+1;
        }
    }
    n=n/10;
    if(n!=0)
    {
        hundreds=n%10;
        for(int j=1;j<=hundreds;j++)
        {
            num[len]='B';
            len=len+1;
        }
    }
    for(int j=len-1;j>=0;j--)
        cout<

8.

#include 
using namespace std;
int main()
{
    int A[200];
    int N;
    int M;
    cin>>N>>M;
    for(int i=0;i>A[i];
    for(int i=0;i=M;i--)
        A[i]=A[i-M];
    for(int i=0;i

9.

#include 
#include 
#include 
using namespace std;
int main()
{
    string s1;
    getline(cin,s1);
    int len;
    len=s1.length();
    char S[80][80];
    for(int i=0;i<80;i++)
        for(int j=0;j<80;j++)
        S[i][j]=' ';
    int j=0;
    int m=0;
    for(int i=0;i0;n--)
    {
        int j=0;
        do{
        j++;}while(S[n][j]!=' ');
        /*cout<

11.

#include 
using namespace std;
int main()
{
    class Number{
public:
    long A;
    long B;
    long C;};
    int T;
    cin>>T;
    Number N[10];
    for(int i=0;i>N[i].A>>N[i].B>>N[i].C;
    for(int i=0;iN[i].C)
            cout<<"Case #"<

13.

#include 
#include 
using namespace std;
const int maxn=1000001;
int prime[maxn],num=0;
bool p[maxn]={0};
void Find_Prime(int n){
for(int i=2;i=n) break;
            for(int j=i+1;j>m>>n;
    Find_Prime(n);
    for(int i=m;i<=n;i++){
        cout<

16.

#include 
#include 
using namespace std;
int main()
{
    string A,B;
    int a,b,pa,pb;
    cin>>A>>a>>B>>b;
    int len_A=0;
    int len_B=0;
    do
    {len_A=len_A+1;
    }while(A[len_A]!='\0');
    do
    {len_B=len_B+1;
    }while(B[len_B]!='\0');
    int len_a=0;
    int len_b=0;
    for(int i=0;i

20.

#include 
#include 
#include 
using namespace std;
bool cmp(double a,double b)
    {
        return a>b;
    }
int main()
{
    class Yuebing{
public:
    int kucunliang;
    int zongshoujia;};
    int N;
    int Max;
    cin>>N>>Max;
    Yuebing X[1000];
    for(int i=0;i>X[i].kucunliang;
    for(int i=0;i>X[i].zongshoujia;
    double A[1000];
    double B[1001];
    for(int i=0;i=X[j].kucunliang)
                {
                    shouyi=shouyi+X[j].zongshoujia;
                    Max=Max-X[j].kucunliang;
                    //cout<

21.

#include 
#include 
#include 
using namespace std;
int main()
{
    int a[10]={0,0,0,0,0,0,0,0,0,0};
    string s;
    cin>>s;
    int num=0;
    do{
        num++;
    }while(s[num]!='\0');
    for(int i=0;i

22.

#include 
#include 
using namespace std;
int main()
{
    int A,B,D;
    cin>>A>>B>>D;
    int sum;
    sum=A+B;
    int new_sum=0;
    int yushu;
    int i=0;
    do{
        yushu=sum%D;
        //cout<<"yushu:"<

23

#include 
using namespace std;

int main(){
    int a[10];
    for( int i = 0; i < 10; i++){
            cin>>a[i];
    }
    for( int i = 0; i < 10; i++){
        if( i != 0 && a[i] != 0){
            cout<

26.

#include 
#include 
using namespace std;
int main()
{
    int c1,c2;
    int hh,mm,ss;
    cin >> c1 >> c2;
    int sum;
    int CLK_TCK=100;
    float r;
    sum = (c2 - c1)/CLK_TCK;
    r = (c2 - c1)%CLK_TCK;
    if (r >=50) sum++;
    hh = sum / 3600;
    sum = sum % 3600;
    mm = sum / 60;
    ss = sum % 60;
    cout<

27.

#include 
using namespace std;
int main()
{
    int N;
    char x;
    cin>>N>>x;
    int sum=0;
    int i;
    for(i=1;sum<=N;i++)
        {sum=(sum+i)*2-1;
        cout<<"i:"<

29.

#include 
#include 
#include 
using namespace std;
int main()
{
    string s1,s2;
    getline(cin,s1);
    getline(cin,s2);
    int L1=s1.length();
    int L2=s2.length();
    char s3[80];
    int j=0;
    int m=0;
    for(int i=0;i'a' and s3[i]<'z')
        {
            s3[i]=s3[i]-32;
        }
    }
    int n[80];
    for(int i=0;i

32.

#include 
using namespace std;
int main()
{
    int N;
    cin>>N;
    int num;
    int chengji;
    //学校从1开始连续编号
    int CJ[100001];
    for(int i=0;i<100001;i++)
        CJ[i]=0;
    for(int i=0;i>num>>chengji;
        CJ[num]=CJ[num]+chengji;
    }
    int max=-1;
    for(int i=0;i<100001;i++)
    {
        if(CJ[i]>max)
            max=CJ[i];
    }
    for(int i=0;i<=100000;i++)
        if(CJ[i]==max)
            cout<

36.

#include 
using namespace std;
int main()
{
    int N;
    char C;
    cin>>N>>C;
    for(int i=1;i<=N;i++)
        cout<

37.

#include 
using namespace std;
int main()
{
    int g1,s1,k1,g2,s2,k2;
    //解决输入的问题
    char x='.';
    int P,A,money;
    cin>>g1>>x>>s1>>x>>k1;
    cin>>g2>>x>>s2>>x>>k2;
    P=g1*17*29+s1*29+k1;
    A=g2*17*29+s2*29+k2;
    //全部换成最便宜的货币
    money=A-P;
    if(money<0)
    {
        money=-money;
        cout<<"-"<

40.

#include 
#include 
#include 
using namespace std;
const int MAXN=10010;
const int MOD=100000007;
char str[MAXN];
int leftNump[MAXN]={0};
int main()
{
    cin>>str;
    int len=sizeof(str);
    for(int i=0;i0)
        {
            leftNump[i]=leftNump[i-1];
        }
        if(str[i]=='P')
        {
            leftNump[i]++;
        }
    }
    int ans=0,rightNumT=0;
    for(int i=len-1;i>=0;i--){
        if(str[i]=='T'){
            rightNumT++;
        }else if(str[i]=='A'){
        ans=(ans +leftNump[i]*rightNumT)%MOD;
        }
    }
    cout<

41.

#include 
#include 
#include 
using namespace std;
int main()
{
    class Student{
public:
    string kaohao;
    int jishi;
    int kaoshi;};
    Student a[1000];
    int N;
    cin>>N;
    for(int i=0;i>a[i].kaohao>>a[i].jishi>>a[i].kaoshi;}
    int num;
    cin>>num;
    int jishizuoweihao[1000];
    for(int i=0;i>jishizuoweihao[i];
    for(int i=0;i

46.

#include 
using namespace std;
int main()
{
    class huaquan{
public:
    int jiahan;
    int jiahua;
    int yihan;
    int yihua;};
huaquan a[100];
int N;
cin>>N;
for(int i=0;i>a[i].jiahan>>a[i].jiahua>>a[i].yihan>>a[i].yihua;
int jia=0;
int yi=0;
for(int i=0;i

 

你可能感兴趣的:(c++/c)