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");
    }
}
總的來說,題目都很水,重點在提高基礎能力。





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章