Announcement

Collapse
No announcement yet.

[Hè 2016] - Trao đổi Cuộc thi Lập trình UIT ACM Online lần 1

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 14520674
    replied
    Câu A
    Code:
    #include <string>
    #include <iostream>
    using namespace std;
    
    
    char cal(char x, char y)
    {
        char r=x+(y-'A');
        if(r>'Z')
            r=r-26;
        return r;
    }
    
    
    int main()
    {
        string s1, s2;
        int n;
        cin >> n;
        while((--n)>=0)
        {
            cin >> s1 >> s2;
            for(int i=0; i<s2.length(); i++)
                s2[i]=cal(s2[i],s1[i%s1.length()]);
            cout << s2 << endl;
        }
        return 0;
    }

    Leave a comment:


  • 14520903
    replied
    Câu A:
    Code:
    #include<bits/stdc++.h>
    using namespace std;
    
    int T,N,M;
    char S[1000010],K[1000010];
    
    
    int main()
    {
        scanf("%d",&T);
    
        while(T--)
        {
            scanf("%s%s",K,S);
    
            N=strlen(K);
            M=strlen(S);
    
            for(int i=0;i<M;i++)
                printf("%c",char((S[i]+K[i%N]-'A'-'A')%26+'A'));
    
            printf("\n");
        }
    }
    Câu C:
    Code:
    #include<bits/stdc++.h>
    using namespace std;
    
    long long a[2010];
    long long b[4000010];
    
    long long i,j,N,Count;
    
    int main()
    {
        scanf("%lld",&N);
    
        for(i=0;i<N;i++)
        {
            scanf("%lld",&a[i]);
            a[i]+=1000000;
        }
    
        for(i=1;i<N-1;i++)
            for(j=0;j<i;j++)
                b[a[i]+a[j]]++;
    
        for(i=N-2;i>=0;i--)
        {
            for(j=0;j<i;j++)
            {
                b[a[i]+a[j]]--;
            }
    
            for(j=i+1;j<N;j++)
            {
                Count+=b[4000000-a[i]-a[j]];
            }
        }
    
        printf("%lld",Count);
    }
    Câu F:
    Code:
    #include<bits/stdc++.h>
    using namespace std;
    
    unsigned long long N,B,A;
    
    int main()
    {
        scanf("%llu%llu%llu",&A,&B,&N);
    
        printf("%llu",(A/N+!!(A%N))*(B/N+!!(B%N)));
    }
    Câu G:
    Code:
    #include<bits/stdc++.h>
    using namespace std;
    
    string s[100000];
    int i;
    int main()
    {
        while(cin>>s[i++]);
        i--;
        while((--i)>=0)
            cout<<s[i]<<' ';
    }

    Leave a comment:


  • 14520820
    replied
    Câu A:
    Code:
    #include<bits/stdc++.h>
    using namespace std;
    
    char a[10000000];
    char b[10000000];
    
    int main()
    {
        int i, k, t, n, na, nb;
        scanf("%d", &n);
        while(n--)
        {
            scanf("%s %s", &a, &b);
            na = strlen(a);
            nb = strlen(b);
            k = 0;
            for(i = 0; i < nb; i++)
            {
                t = b[i]+(a[k]-'A')%26;
                if(t > 'Z')
                    t -= 26;
                b[i] = t;
                k = (k + 1)%na;
            }
            printf("%s\n", b);
        }
        return 0;
    }
    Code:
    #include<bits/stdc++.h>
    using namespace std;
    
    char a[10000000];
    char b[10000000];
    
    int main()
    {
        int i, k, t, n, na, nb;
        scanf("%d", &n);
        while(n--)
        {
            scanf("%s %s", &a, &b);
            na = strlen(a);
            nb = strlen(b);
            k = 0;
            for(i = 0; i < nb; i++)
            {
                t = b[i]+(a[(k++)%na]-'A')%26;
                if(t > 'Z')
                    t -= 26;
                printf("%c", t);
            }
            printf("\n");
        }
        return 0;
    }
    Câu E:
    Code:
    #include<stdio.h>
    #include<string.h>
    
    char s[1000009];
    char tr[1000009];
    
    bool precheck()
    {
        int i, j, n = strlen(s), c = 0;
        for(i = n/2-1; i >= 0; i--)
        {
            if(s[i] < s[n-i-1])
                return false;
            if(s[i] == s[n-i-1])
                c++;
            if(s[i] > s[n-i-1])
                break;
        }
        if(c == n/2)
            return false;
        if(n&1)
            s[n/2+1] = '\0';
        else
            s[n/2] = '\0';
        printf("%s", s);
        for(i = n/2-1; i >= 0; i--)
            printf("%c", s[i]);
        return true;
    }
    
    void inc()
    {
        int i = 0, d = 1, t;
        while(tr[i] != '\0')
        {
            t = tr[i] + d - 48;
            tr[i] = t%10+48;
            d = t/10;
            i++;
        }
        if(d)
        {
            tr[i] = '1';
            tr[i+1] = '\0';
        }
    }
    
    void sol()
    {
        if(!strcmp(s, "9"))
        {
            printf("11");
            return;
        }
        int i, j;
        int n = strlen(s);
        int m = n/2, d = 0;
        if(n&1)
            d = 1;
        for(i = 0; i < m; i++)
        {
            tr[i+d] = s[m-i-1];
        }
        tr[m+d] = '\0';
    
        if(d)
        {
            tr[0] = s[m];
            inc();
            if(strlen(tr) > m+1)
            {
                for(i = m+1; i > 1; i--)
                    printf("%c", tr[i]);
                printf("%s", tr);
                return;
            }
    
            for(i = m; i >= 0; i--)
                printf("%c", tr[i]);
            for(i = 1; i <= m; i++)
                printf("%c", tr[i]);
            return;
        }
        inc();
        if(strlen(tr) > m)
        {
            for(i = m; i > 0; i--)
                printf("%c", tr[i]);
            printf("%s", tr);
            return;
        }
        for(i = m-1; i >= 0; i--)
            printf("%c", tr[i]);
        printf("%s", tr);
    }
    
    int main()
    {
        scanf("%s", &s);
        if(!precheck())
            sol();
    }
    Câu F:
    Code:
    #include<stdio.h>
    
    int main()
    {
        long long u, v, n, x, y, d = 0, rs = 0;
        scanf("%lld %lld %lld", &u, &v, &n);
        if(n == 1)
        {
            printf("%lld", u*v);
            return 0;
        }
        x = (u/n);
        y = (v/n);
        if(v%n == 0 && u % n == 0)
        {
            printf("%lld", x*y);
            return 0;
        }
        if(v%n&& u % n)
        {
            printf("%lld", (x+1)*(y+1));
            return 0;
        }
        if(v%n)
        {
            printf("%lld", (x+0)*(y+1));
            return 0;
        }
        //if(v%n)
        {
            printf("%lld", (x+1)*(y+0));
            return 0;
        }
        return 0;
    }
    Câu G:
    Code:
    #include<iostream>
    #include<sstream>
    #include<string>
    #include<algorithm>
    #include<vector>
    
    using namespace std;
    
    string s;
    string t;
    vector<string> rs;
    
    int main()
    {
        getline(cin, s);
        int i, n;
        istringstream ss(s);
        while (ss>>t)
            rs.push_back(t);
        n = rs.size();
        reverse(rs.begin(), rs.end());
        for(i = 0; i < n; i++)
            cout<<rs[i]<<" ";
    }
    Code:
    #include<iostream>
    #include<sstream>
    #include<string>
    #include<algorithm>
    #include<vector>
    
    using namespace std;
    
    string s;
    string rs[10000009];
    
    int main()
    {
        getline(cin, s);
        int i, n = 0;
        istringstream ss(s);
        while (ss>>rs[n++]);
        for(i = n-2; i >= 0; i--)
            cout<<rs[i]<<" ";
    }
    sáng rảnh sửa lại câu A với G cho bớt ngu hơn cái trong bài thi tí.
    phần sửa dưới phần code trong bài, vẫn dùng ý tưởng cũ
    Last edited by 14520820; 25-08-2016, 07:04. Reason: thêm code

    Leave a comment:


  • 15520426
    replied
    Screenshot (5).png
    Mình chạy cứ báo lỗi này...không biết làm sao..thêm dấu ngoặc tròn gì đâu nhỉ???

    Leave a comment:


  • [Hè 2016] - Trao đổi Cuộc thi Lập trình UIT ACM Online lần 1

    [Hè 2016] - Trao đổi Cuộc thi Lập trình UIT ACM Online lần 1


    Các bạn upload code các bài giải được tại đây để thảo luận nhé.


    Thông tin cuộc thi và kết quả tại Fanpage cuộc thi:
    facebook.com/uit.acm

    Last edited by UIT.ACM; 25-08-2016, 00:39.

LHQC

Collapse
Working...
X