vijos刷题记录

谁拿了最多奖学金 - Vijos

可以直接用结构体来做

#include <iostream>
#include <string>
using namespace std;
struct Student
{
    char name[20];                //姓名
    int score1;                   //期末成绩
    int score2;                   //班级成绩
    char leader;                  //是否是班干部
    char weststudent;             //是否是西部学生
    int article;                  //论文数
    int money;                    //个人总奖金
};
Student a[100];
int main()
{
 
    int max=0;                    //学生编号
    int sum=0;                    //总奖金
    int n;                        //学生总数
    cin>>n;                       //输入学生总数
    for(int i=0; i<n; i++)
    {
        cin>>a[i].name;
        cin>>a[i].score1;
        cin>>a[i].score2;
        cin>>a[i].leader;
        cin>>a[i].weststudent;
        cin>>a[i].article;
    }
    for(int j=0; j<n; j++)
    {
        a[j].money=0;
        if(a[j].score1>80&&a[j].article>=1)
            a[j].money+=8000;
        if(a[j].score1>85&&a[j].score2>80)
            a[j].money+=4000;
        if(a[j].score1>90)
            a[j].money+=2000;
        if(a[j].score1>85&&a[j].weststudent=='Y')
            a[j].money+=1000;
        if(a[j].score2>80&&a[j].leader=='Y')
            a[j].money+=850;
        sum+=a[j].money;
    }
    for(int k=0; k<n; k++)
    {
        if(a[k].money>a[max].money)
            max=k;
    }
    cout<<a[max].name<<endl;
    cout<<a[max].money<<endl;
    cout<<sum;
    return 0;
}

捕风捉影 - Vijos

思路:看样例就可以知道,回文素数

下面是我的代码,过了,注意:偶数位的回文素数不存在

如果有回文数,一定不是素数

#include<iostream>
#include<cmath>
using namespace std;
#define N 100000005
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();
   }
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
bool is_prime(int x)
{
    if(x < 2) return false;
    for(int i = 2;i <= sqrt(x);i++)
    if(x%i == 0) return false;
    
        return true;
}
int panduan(int x)
{
    int len = 0;
    int soso[12];
    while(x)
    {
        soso[len++] = x%10;
        x /= 10;
    }
    for(int i = 0;i<len/2;i++)
    if(soso[i] != soso[len-1-i]) return false;
    return true;
}
int main()
{
    int m = 0,n = 0;
    scanf("%d%d",&m,&n);
for(n>=100000000) n = 9999999;    

if(n > N) n = N;
    for(int i = m;i<=n;i++)
    if(panduan(i) && is_prime(i)) printf("%d\n",i);
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值