美文网首页
ACM刷题打卡-160308简单题

ACM刷题打卡-160308简单题

作者: toedwy | 来源:发表于2016-03-09 17:49 被阅读115次

    ZOJ 1057 - Undercut

    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <cctype>
    #include <cmath>
    #include <vector>
    using namespace std;
    
    int main() {
        int n;
        bool first = true;
    
        while(cin >> n && n != 0) {
            int ap = 0, bp = 0;
            int x = n, y = n;
            vector<int> a;
            vector<int> b;
    
            while(x-- > 0) {
                int temp_a;
                cin >> temp_a;
                a.push_back(temp_a);
            }
    
            while(y-- > 0) {
                int temp_b;
                cin >> temp_b;
                b.push_back(temp_b);
            }
    
            for (int i = 0; i < n; ++i) {
    
                // cout << a[i] << " " << b[i] << endl;
    
                if(a[i] == b[i]) {
                    continue;
                }
                else if(abs(a[i] - b[i]) == 1) {
                    if(a[i] == 1 && b[i] == 2) {
                        ap += 6;
                        continue;
                    }
                    else if(a[i] == 2 && b[i] == 1) {
                        bp += 6;
                        continue;
                    }
                    else if(a[i] > b[i]) {
                        int temp = a[i] + b[i];
                        bp += temp;
                        continue;
                    }
                    else {
                        int temp = a[i] + b[i];
                        ap += temp;
                    }
    
                }
                else{
                    if(a[i] > b[i]) {
                        ap += a[i];
                    }
                    else {
                        bp += b[i];
                    }
                }
            }
            
            if(first) {
                cout << "A has " << ap << " points. B has " << bp << " points." << endl;
                first = false;
            }
            else {
                cout << endl;
                cout << "A has " << ap << " points. B has " << bp << " points." << endl;
                
            }
        }
        return 0;
    }
    

    ZOJ 1178 - Booklet Printing

    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <cctype>
    #include <cmath>
    #include <vector>
    using namespace std;
    
    int main() {
        int page;
        const int INF = 666;
    
        while(cin >> page && page != 0) {
            int blank;
    
            if(page % 4 != 0)
                blank = 4 - (page % 4);
            else
                blank = 0;
    
            vector<int> prints;
            prints.push_back(0);
    
            for (int i = 1; i <= page; ++i) {
                prints.push_back(i);
            }
            for (int j = 0; j < blank; ++j) {
                prints.push_back(INF);
            }
    
            cout << "Printing order for " << page << " pages:" << endl;
            int round = page + blank;
            int sheet = 1;
            for (int k = 1; k <= round / 2; ++k) {
                if(k % 2 != 0) {
                    if(prints[round + 1 - k] * prints[k] != 443556) {
                        cout << "Sheet " << sheet << ", front: ";
                        if(prints[round + 1 - k] == 666)
                            cout << "Blank";
                        else
                            cout << prints[round + 1 - k];
                        cout << ", ";
    
                        if(prints[k] == 666)
                            cout << "Blank";
                        else
                            cout << prints[k];
                        cout << endl;
                    }
                }
                else {
                    if(prints[round + 1 - k] * prints[k] != 443556) {
                        cout << "Sheet " << sheet << ", back : ";
                        if(prints[k] == 666)
                            cout << "Blank";
                        else
                            cout << prints[k];
                        cout << ", ";
    
                        if(prints[round + 1 - k] == 666)
                            cout << "Blank";
                        else
                            cout << prints[round + 1 - k];
                        cout << endl;
                    }
                    sheet++;
                }
            }
        }
    
        return 0;
    }
    

    ZOJ 1195 - Blowing Fuses

    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <cctype>
    #include <cmath>
    #include <vector>
    using namespace std;
    
    int main() {
        int n, m, c;
        int cnt = 1;
        while(cin >> n >> m >> c && n + m + c != 0) {
            vector<int> devices;
            vector<bool> status;
            devices.push_back(0);
            status.push_back(false);
            int max = 0;
    
            bool blown = false;
    
            for (int i = 1; i <= n; ++i) {
                int d;
                cin >> d;
                devices.push_back(d);
                status.push_back(false);
            }
            for (int j = 1; j <= m; ++j) {
                /*
                if(blown) {
                    break;
                }
                */
                int num;
                cin >> num;
                status[num] = !status[num];
                int now = 0;
    
                for (int k = 1; k <= n; ++k) {
                    if(status[k]) {
                        now += devices[k];
                    }
                    if(now > c) {
                        blown = true;
                        break;
                    }
                    if(now > max) {
                        max = now;
                    }
                }
            }
    
    
            cout << "Sequence " << cnt << endl;
    
    
            cnt++;
    
            if(blown) {
                cout << "Fuse was blown." << endl;
            }
            else {
                cout << "Fuse was not blown." << endl;
                cout << "Maximal power consumption was " << max << " amperes." << endl;
            }
            
            cout << endl;
        }
    
        return 0;
    }
    

    ZOJ 1350 - The Drunk Jailer

    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <cctype>
    #include <cmath>
    #include <vector>
    using namespace std;
    
    int main() {
        int n, m, c;
        int cnt = 1;
        while(cin >> n >> m >> c && n + m + c != 0) {
            vector<int> devices;
            vector<bool> status;
            devices.push_back(0);
            status.push_back(false);
            int max = 0;
    
            bool blown = false;
    
            for (int i = 1; i <= n; ++i) {
                int d;
                cin >> d;
                devices.push_back(d);
                status.push_back(false);
            }
            for (int j = 1; j <= m; ++j) {
                /*
                if(blown) {
                    break;
                }
                */
                int num;
                cin >> num;
                status[num] = !status[num];
                int now = 0;
    
                for (int k = 1; k <= n; ++k) {
                    if(status[k]) {
                        now += devices[k];
                    }
                    if(now > c) {
                        blown = true;
                        break;
                    }
                    if(now > max) {
                        max = now;
                    }
                }
            }
    
    
            cout << "Sequence " << cnt << endl;
    
    
            cnt++;
    
            if(blown) {
                cout << "Fuse was blown." << endl;
            }
            else {
                cout << "Fuse was not blown." << endl;
                cout << "Maximal power consumption was " << max << " amperes." << endl;
            }
            
            cout << endl;
        }
    
        return 0;
    }
    

    ZOJ 1622 - Switch

    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <cctype>
    #include <cmath>
    #include <vector>
    using namespace std;
    
    int main() {
        int num;
        while(scanf("%d",&num) != EOF) {
            vector<int> lights;
            for (int i = 0; i < num; ++i) {
                int temp;
                cin >> temp;
                lights.push_back(temp);
            }
            int onezero = 0;
            int zeroone = 0;
    
            for (int j = 0; j < lights.size(); ++j) {
                if(j % 2 == 0) {
                    if(lights[j] != 1)
                        onezero++;
                    else
                        zeroone++;
                }
                else {
                    if(lights[j] != 1)
                        zeroone++;
                    else
                        onezero++;
                }
            }
    
            cout << (zeroone < onezero ? zeroone : onezero) << endl;
        }
    
        return 0;
    }
    

    ZOJ 1858 - Soundex

    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <cctype>
    #include <cmath>
    #include <vector>
    using namespace std;
    
    int main() {
        const string letter = "BFPVCGJKQSXZDTLMNR";
        string line;
        while(getline(cin, line)) {
            vector<int> code;
            vector<bool> flag;
    
            for (int i = 0; i < line.length(); ++i) {
                flag.push_back(true);
                bool find = false;
                for (int j = 0; j < letter.size(); ++j) {
                    if(letter[j] == line[i]) {
                        find = true;
                        if(j >= 0 && j < 4) {
                            code.push_back(1);
                        }
                        else if(j >= 4 && j < 12) {
                            code.push_back(2);
                        }
                        else if(j >= 12 && j < 14) {
                            code.push_back(3);
                        }
                        else if(j == 14) {
                            code.push_back(4);
                        }
                        else if(j >= 15 && j < 17) {
                            code.push_back(5);
                        }
                        else if(j == 17) {
                            code.push_back(6);
                        }
                    }
                }
                if(!find) {
                    code.push_back(0);
                }
            }
    
            if(code[0] == 0)
                flag[0] = false;
    
            for (int k = 1; k < code.size(); ++k) {
                if(code[k] == code[k - 1] || code[k] == 0)
                    flag[k] = false;
            }
    
            for (int l = 0; l < code.size(); ++l) {
                if(flag[l])
                    cout << code[l];
            }
    
            cout << endl;
        }
    
        return 0;
    }
    

    ZOJ 2208 - To and Fro

    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <cctype>
    #include <cmath>
    #include <vector>
    using namespace std;
    
    int main() {
        int col;
        string line;
        while(cin >> col && col != 0) {
    
            cin >> line;
            int seg = 2 * col;
    
            for (int i = 0; i < (seg - i); ++i) {
    
                int j = 0;
                while (j < line.length()) {
                    cout << line[i + j];
                    if((seg - i - 1 + j) < line.length())
                        cout << line[(seg - i - 1) + j];
                    j += seg;
                }
            }
            cout << endl;
        }
    
        return 0;
    }
    

    ZOJ 2812 - Quicksum

    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <cctype>
    #include <cmath>
    #include <vector>
    using namespace std;
    
    int main() {
        string line;
        while(getline(cin, line) && line[0] != '#') {
            int sum = 0;
            for (int i = 0; i < line.length(); ++i) {
                if(isalpha(line[i])) {
                    int value = (line[i] - 'A' + 1) * (i + 1);
                    sum += value;
                }
            }
    
            cout << sum << endl;
        }
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:ACM刷题打卡-160308简单题

          本文链接:https://www.haomeiwen.com/subject/veftlttx.html