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

这样子居然AC了……

Posted by analysiser at 2009-07-18 12:30:32 on Problem 3438
没想到string.push_back(int)会把int转成ASC2码然后给我输出一堆乱码…… 最后又建了一个数组……
//3438  Look and Say
#include<iostream>
#include<string>
using namespace std;

void getElem(string list)
{
    int presentNum=list[0];
    int S[1001]={0};
    int sum=0;
    int j=0;
    string res;
    for(int i=0;i<list.length();i++)
    {
        //cout<<list[i]<<endl;
        if(list[i]==presentNum)   ++sum;
        else
        {
            S[j]=sum;
            ++j;
            //res+=sum;
            res.push_back(presentNum);
            presentNum=list[i];
            sum=1;
        }
    }
    for(int k=0;k<res.length();k++)
    {
        cout<<S[k]<<res[k]; //傻死了……T_T
    }
    cout<<endl;
}

int main()
{
    int n,i=0;
    cin>>n;
    while(i!=n)
    {
        string str;
        cin>>str;
        str.push_back(1); //结束标记
        getElem(str); 
        ++i;
    }
    system("pause");
    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