Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

把讨论里的数据都过了,可我还没过。。。谁来帮忙下。。。。

Posted by happyface at 2009-01-18 00:27:53 on Problem 2845
/* 
 * File:   POJ-2845.cpp
 * Author: Administrator
 *
 * Created on 2009��1��17��, ����10:56
 */

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <iostream>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <string>
#include <complex>
#include <functional>
#include <algorithm>
#include <sstream>
#include <bitset>
#include <fstream>
using namespace std;

int main() {
    int n;
    while (scanf("%d", &n) != EOF && n != 0) {
        int d = 1;
        while (n--) {
            string s1, s2;
            cin >> s1 >> s2;
            string s;
            int tmp = 0;
            int res = 0;
            int i, j;
            int label = 0;
            i = s1.size() - 1;
            j = s2.size() - 1;
            while (1) {
                res = 0;
                if (i >= 0) {
                    if (s1[i] == '1')res++;
                    i--;
                }
                if (j >= 0) {
                    if (s2[j] == '1')res++;
                    j--;
                }
                if (tmp) {
                    res++;
                    tmp = 0;
                }
                //                printf("%d %d ", res, tmp);
                //                printf("\n");
                if (res == 0) {
                    s.push_back('0');
                    tmp = 0;
                } else if (res == 1) {
                    s.push_back('1');
                    tmp = 0;
                    label++;
                } else if (res == 2) {
                    s.push_back('0');
                    tmp = 1;
                    label++;
                } else {
                    s.push_back('1');
                    tmp = 1;
                    label++;
                }
                if (i < 0 && j < 0) {
                    if (tmp)s.push_back('1');
                    //                    cout<<s<<endl;
                    break;
                }
            }
            printf("%d ", d++);
            if (label) {
                for (int i = s.size() - 1; i >= 0; i--) {
                    if (s[i] == '0' && label != 0)continue;
                    printf("%c", s[i]);
                    label = 0;
                }
            } else printf("0");
            printf("\n");
        }
    }
    return 0;
}







Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator