NYOJ 277.458.463.484.558

277

#include<iostream>

#include<cstring>
using namespace std;
int main()
{
int n,m,i;
char c[6],temp[6];//temp保存最小值 
cin>>n;
while(n--)
{
cin>>m;
getchar();
gets(temp);//相当于把第一个车牌号赋给temp 
while(--m)
{
gets(c);
if(strcmp(c,temp)<0)
{
strcpy(temp,c);
}
}
puts(temp);
}
return 0;

}


458

*******************************************************************************************************************************
其实这个题不难,但还是不会的原因是不知道同余定理,或者是不懂同余定理。

      思路第一个光棍数是471=>以后的每个光棍数x的后三位都是471=> x%1000=471 

      则由同余定理得 471≡x mod 1000=> x=1000k+471.

同余定理:

数学上的记法为:
a≡ b(mod d)
可以看出当n<d的时候,所有的n都对d同商,比如时钟上的小时数,都小于12,所以小时数都是模12的同商.
对于同余有三种说法都是等价的,分别为:
(1) a和b是模d同余的.
(2) 存在某个整数n,使得a=b+nd .
(3) d整除a-b.
可以通过换算得出上面三个说法都是正确而且是等价的.
证明 (1)、(2)、(3)等价:
m=a%d==b%d;
(a-m)=x*d;
(b-m)=y*d;
a-m-b+m=(x-y)*d;
*************************************************************************************************************************************
代码:

#include <stdio.h>
int main()
{
    long long n,m;
    scanf("%lld",&n);
    while(n--)
    {
        scanf("%lld",&m);
        printf("%lld\n",1000*(m-1)+471);
    }
    return 0;
 } 

#include<iostream>
using namespace std;
int main()
{

long long n,i,m,h;
cin>>n;
while(n--)
{
cin>>m;
int sum=0;
for(i=471;i<=9999;i++)
{
h=i*i*i;
if(h%1000==111)
{
sum++;
if(sum==m)
cout<<i<<endl;
}
}
}
return 0;

}

463

#include <iostream> 
using namespace std;  
int main()  
{  
    int n,m,i,j;
    cin>>n;
    while(n--)
    {
    cin>>m;
    for(i=1;i<=m;i++)
    {
    for(j=i;j<=9;j++)
    {
    cout<<i<<"*"<<j<<"="<<i*j<<" ";
}
cout<<endl;
}
}
return 0;  
}  


484

#include <stdio.h>
#include <string.h>
int main()
{
int n=0;
char a[5];
while(scanf("%s",a)!=EOF)
{
n++;
printf("Case %d: ",n);
if(strcmp(a,"I")==0)
printf("1\n");
else if(strcmp(a,"II")==0)
printf("2\n");
else if(strcmp(a,"III")==0)
printf("3\n");
else if(strcmp(a,"IV")==0)
printf("4\n");
else if(strcmp(a,"V")==0)
printf("5\n");
else if(strcmp(a,"VI")==0)
printf("6\n");
else if(strcmp(a,"VII")==0)
printf("7\n");
else if(strcmp(a,"VIII")==0)
printf("8\n");
else if(strcmp(a,"IX")==0)
printf("9\n");
else if(strcmp(a,"X")==0)
printf("10\n");
else if(strcmp(a,"XI")==0)
printf("11\n");
else if(strcmp(a,"XII")==0)
printf("12\n");
}
return 0;
}

497

#include <iostream>
#include<algorithm>  
using namespace std;  
int main()  
{  
    int t,n,p,i,a[105],sum;  
    cin>>t;
    while(t--)
    {  
        cin>>n;
        p=n;
        for(i=0;i<n;i++)
        {
        cin>>a[i];
}
sort(a,a+n);
sum=0;
for(i=0;i<n;i++)
{
sum=sum+a[i]*p;
p--;
}
cout<<sum<<endl;
    }  
    return 0;  
}  



558

#include<iostream>

#include<stdio.h>//不加会错

#include<cstring>
using namespace std;
int main()
{
int n;
char c[6];
cin>>n;
getchar();
while(n--)
{
gets(c);
if((strlen(c))>3)
cout<<"3"<<endl;
else 
{
if ((c[0]=='o' && c[1]=='n') || (c[1]=='n' && c[2]=='e') || (c[0]=='o' && c[2]=='e'))
cout<<"1"<<endl;
else
cout<<"2"<<endl;
}
}
return 0;

}

猜你喜欢

转载自blog.csdn.net/tingtingyuan/article/details/80147733