1. 程式人生 > >命令列選項(0分....)

命令列選項(0分....)

emmmmm,,,不知道哪兒沒考慮到.......改了好多次... 

#include <iostream>
#include <cstdio>
#include <map>
#include <cstring>
#include <vector>
#include <cmath>

using namespace std;

char delimiter[] = " ";
//typedef pair<char, int> PAIR;
int main()
{
    string s;

    map<char, int> a;
    cin >> s;

    for(int i=0; s[i]; i++){
        if(islower(s[i]) && s[i]!=':' || isdigit(s[i]))
        a[s[i]] = -2;
    }

    int n;

    cin >> n;
    getchar();
    for(int i=0; i<n; i++){

        char* temp;


        gets(temp);
        //處理字串

        char *t;
        t = strtok(temp, " ");

        char *p;


        while(t) {
            if (t[2] == '\0') {
                if (t[0] == '-') {

                    if(a[t[1]] < 0)
                        a[t[1]] = -1;
                    else if(a[t[1]] == 0)
                        break;
                        p = t;
                }
                else if (isdigit(t[0])) {
                    int j = 0, tmp = 0;
                    while (t[j]) {
                        tmp *= 10;
                        tmp += t[j] - '0';
                        j++;
                    }
                    a[p[1]] = tmp;
                }

                t = strtok(NULL, " ");
                //   cout << t << endl;
            }
            else break;
        }


        cout << "Case " << i+1 << ": ";

    /*    for(map<char, int>::iterator it = a.begin(); it != a.end(); it++){
                cout << "-" << it->first << " " << it->second << endl;
            }
*/
        for(map<char, int>::iterator it = a.begin(); it != a.end(); it++){
            if(it->second == -1){
                cout << "-" << it->first << " ";
                it->second = -2;
            }
            if(it -> second > 0){
                cout << "-" << it->first << " " << it->second << " ";
                it ->second = -2;
            }
        }
        cout << endl;
    }

    return 0;
}
#include <iostream>
#include <cstdio>
#include <map>
#include <cstring>
#include <vector>
#include <cmath>

using namespace std;

//char delimiter[] = " ";
//typedef pair<char, int> PAIR;
int main()
{
    string s;

    map<char, int> a;
    cin >> s;

    for(int i=0; s[i]; i++){
        if(s[i+1]!=':')
        a[s[i]] = -2;
        else a[toupper(s[i])] = -3;
    }

    int n;

    cin >> n;
    getchar();
    for(int i=0; i<n; i++){

        char* temp;


        gets(temp);
        //處理字串

        char *t;
        t = strtok(temp, " ");

        char *p;


        while(t) {
            if (t[2] == '\0') {
                if (t[0] == '-') {

                    if(a[t[1]] < 0)
                        a[t[1]] = -1;
                    else if(a[t[1]] == 0)
                        break;
                        p = t;
                }
                else if (isdigit(t[0])) {
                    int j = 0, tmp = 0;
                    while (t[j]) {
                        tmp *= 10;
                        tmp += t[j] - '0';
                        j++;
                    }
                    if(a[toupper(p[i])] == -3 || a[toupper(p[i])] > 0 )
                    a[p[1]] = tmp;
                    else break;
                }

                t = strtok(NULL, " ");
                //   cout << t << endl;
            }
            else break;
        }


        cout << "Case " << i+1 << ": ";

    /*    for(map<char, int>::iterator it = a.begin(); it != a.end(); it++){
                cout << "-" << it->first << " " << it->second << endl;
            }
*/
        for(map<char, int>::iterator it = a.begin(); it != a.end(); it++){
            if(it->second == -1){
                cout << "-" << it->first << " ";
                it->second = -2;
            }
            if(it -> second > 0){
                cout << "-" << it->first << " " << it->second << " ";
                it ->second = -2;
            }
        }
        cout << endl;
    }

    return 0;
}
#include <iostream>
#include <cstdio>
#include <map>
#include <cstring>
#include <vector>
#include <cmath>

using namespace std;

//char delimiter[] = " ";
//typedef pair<char, int> PAIR;
int main()
{
    string s;

    map<char, int> a;
    cin >> s;

    for(int i=0; s[i]; i++){
        if(s[i+1]!=':')
            a[s[i]] = -2;
        else a[toupper(s[i])] = -3;
    }

    int n;

    cin >> n;
    getchar();
    for(int i=0; i<n; i++){

        char* temp;


        gets(temp);
        //處理字串

        char *t;
        t = strtok(temp, " ");

        char *p;


        while(t) {
            if (t[2] == '\0') {
                if (t[0] == '-') {

                    if(a[t[1]] < 0)
                        a[t[1]] = -1;
                        else if(a[toupper(t[1])]<0)
                                a[toupper(t[1])] = -1;
                    else if(a[t[1]] == 0)
                        break;
                    p = t;
                }
                else if (isdigit(t[0])) {
                    int j = 0, tmp = 0;
                    while (t[j]) {
                        tmp *= 10;
                        tmp += t[j] - '0';
                        j++;
                    }
                    if(a[toupper(p[1])] == -1 || a[toupper(p[1])] > 0 )
                        a[p[1]] = tmp;
                    else break;
                }

                t = strtok(NULL, " ");
                //   cout << t << endl;
            }
            else break;
        }


        cout << "Case " << i+1 << ": ";

        /*    for(map<char, int>::iterator it = a.begin(); it != a.end(); it++){
                    cout << "-" << it->first << " " << it->second << endl;
                }
    */
        for(map<char, int>::iterator it = a.begin(); it != a.end(); it++){
            if(it->second == -1){
                if(isupper(it -> first))
                    ;

                else
                cout << "-" << it->first << " ";
                it->second = -2;
            }
            if(it -> second > 0){
                cout << "-" << it->first << " " << it->second << " ";
                it ->second = -2;
            }
        }
        cout << endl;
    }

    return 0;
}