Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
这样子居然AC了……没想到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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator