ACM竞赛-516 round#5 部分题解

    昨晚举办了516寝室的第五场竞赛,题目很水,但也很基础,题目网址https://cn.vjudge.net/contest/217247#problem/A   密码 516... 下面直接上题:

    第一题很水,看第二题

求实数的绝对值。
Input输入数据有多组,每组占一行,每行包含一个实数。Output对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数。Sample Input
123
-234.00
Sample Output
123.00
234.00
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    double a,b,c,d,e;
    while(~scanf("%lf",&a))
    {
        if(a<0)b=-a;
        else b=a;
        printf("%.2lf\n",b);
    }

}

Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).

In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
InputThe input will consist of a series of integers n, one integer per line.
OutputFor each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.
Sample Input
1
100
Sample Output
1

5050
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll a,b,c,d,e;
    while(~scanf("%lld",&a))
    {
        b=0;
        for(int i=1;i<=a;i++)
        {
            b+=i;

        }
        printf("%lld\n",b);
        printf("\n");
    }

}

E题

we define f(A) = 1, f(a) = -1, f(B) = 2, f(b) = -2, ... f(Z) = 26, f(z) = -26;
Give you a letter x and a number y , you should output the result of y+f(x).
InputOn the first line, contains a number T.then T lines follow, each line is a case.each case contains a letter and a number.Outputfor each case, you should the result of y+f(x) on a line.Sample Input
6
R 1
P 2
G 3
r 1
p 2
g 3
Sample Output
19
18
10
-17
-14
-4

using namespace std;
typedef long long ll;
int main()
{
    ll a,c,d,e,f;
    char b;
    scanf("%lld",&a);
    while(a>0)
    {   getchar();
        b=getchar();
        scanf("%lld",&c);
        if(b>=97)printf("%lld\n",96-b+c);
        else printf("%lld\n",b-64+c);
        a--;
    }


}

F题

There are many lamps in a line. All of them are off at first. A series of operations are carried out on these lamps. On the i-th operation, the lamps whose numbers are the multiple of i change the condition ( on to off and off to on ).
InputEach test case contains only a number n ( 0< n<= 10^5) in a line.
OutputOutput the condition of the n-th lamp after infinity operations ( 0 - off, 1 - on ).Sample Input
1
5
Sample Output
1
0


        
  

Consider the second test case:

The initial condition	   : 0 0 0 0 0 …
After the first operation  : 1 1 1 1 1 …
After the second operation : 1 0 1 0 1 …
After the third operation  : 1 0 0 0 1 …
After the fourth operation : 1 0 0 1 1 …
After the fifth operation  : 1 0 0 1 0 …

The later operations cannot change the condition of the fifth lamp any more. So the answer is 0.
Hint
hint
        
 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
     ll a,b,c;
     while(~scanf("%lld",&a))
     {
         b=0;
         for(int i=1;i<=a;i++)
              if(a%i==0)b++;
        c=b%2;
        printf("%lld\n",c);
     }
}

F题重点在思路!!!!一定要仔细看

G题

网上流传一句话:"常在网上飘啊,哪能不挨刀啊~"。其实要想能安安心心地上网其实也不难,学点安全知识就可以。

首先,我们就要设置一个安全的密码。那什么样的密码才叫安全的呢?一般来说一个比较安全的密码至少应该满足下面两个条件:

(1).密码长度大于等于8,且不要超过16。
(2).密码中的字符应该来自下面“字符类别”中四组中的至少三组。

这四个字符类别分别为:
1.大写字母:A,B,C...Z;
2.小写字母:a,b,c...z;
3.数字:0,1,2...9;
4.特殊符号:~,!,@,#,$,%,^;

给你一个密码,你的任务就是判断它是不是一个安全的密码。
Input输入数据第一行包含一个数M,接下有M行,每行一个密码(长度最大可能为50),密码仅包括上面的四类字符。Output对于每个测试实例,判断这个密码是不是一个安全的密码,是的话输出YES,否则输出NO。Sample Input
3
a1b2c3d4
Linle@ACM
^~^@^@!%
Sample Output
NO
YES
NO

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll a,b,c,d,e,f,l;
    l=0;
    char s[51];
    scanf("%lld",&a);
     getchar();
    for(int i=0;i<a;i++)
   {    b=0;c=0;d=0;e=0;
        gets(s);
        l=strlen(s);
        if(l<8||l>16) printf("NO\n");
        else{
        for(int i=0;i<l;i++)
        {

            if(s[i]<=122&&s[i]>=97)b=1;
            if(s[i]<=90&&s[i]>=65)c=1;
            if(s[i]<=57&&s[i]>=48)d=1;
            if(s[i]=='~'||s[i]=='!'||s[i]=='@'||s[i]=='#'||s[i]=='$'||s[i]=='%'||s[i]=='^')e=1;
        }
        if(b+c+d+e>=3)printf("YES\n");
        else printf("NO\n");
        }


    }

}

H题

Give you a number on base ten,you should output it on base two.(0 < n < 1000)
InputFor each case there is a postive number n on base ten, end of file.OutputFor each case output a number on base two.Sample Input
1
2
3
Sample Output
1
10
11

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
   int a[100];
   ll n;
   while(~scanf("%lld",&n))
   {

    int i=0;
    a[i]=n%2;
    n=n/2;
    while(n)
    {
    i++;
    a[i]=n%2;
    n=n/2;
    }
    for(int j=i;j>=0;j--)
    printf("%d",a[j]);
    printf("\n");


   }
}

I题

Give you the width and height of the rectangle,darw it.
InputInput contains a number of test cases.For each case ,there are two numbers n and m (0 < n,m < 75)indicate the width and height of the rectangle.Iuput ends of EOF.OutputFor each case,you should draw a rectangle with the width and height giving in the input.
after each case, you should a blank line.Sample Input
3 2
Sample Output
+---+
|   |
|   |
+---+

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll a,b,c,d,e;
    while(~scanf("%lld %lld",&a,&b))
    {
        printf("+");
        for(int i=0;i<a;i++)
            printf("-");
        printf("+\n");
        for(int j=0;j<b;j++)
        {
            printf("|");
            for(int i=0;i<a;i++)
                printf(" ");
             printf("|\n");
        }
         printf("+");
        for(int i=0;i<a;i++)
            printf("-");
        printf("+\n");
        printf("\n");
    }
}
总的来说,题目都很水,重点在提高基础能力。





猜你喜欢

转载自blog.csdn.net/monster_ayb/article/details/79610363