NYOJ-525 一道水题【模拟】
2012-04-11 15:32
281 查看
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=525
解题思路:
用到了字符串截取函数strtok
本来想用sscanf的正则表达式的,但是不会写。。。百度了一下,知道了大概,貌似不能对数字用。估计能把(没仔细找~~)
代码如下:
解题思路:
用到了字符串截取函数strtok
本来想用sscanf的正则表达式的,但是不会写。。。百度了一下,知道了大概,貌似不能对数字用。估计能把(没仔细找~~)
代码如下:
#include <iostream> #include <cstring> #include<stdio.h> #include<string> #include<algorithm> using namespace std; const int N = 5010; char str ; string ans ; bool cmp(string a, string b) { int lena = a.size(), lenb = b.size(); if(lena != lenb) return lena < lenb; else { for(int i = 0; i < lena; ++i) if(a[i] != b[i]) return a[i] < b[i]; } } int main() { int len, i, j, k, num; while(scanf("%s", str) != EOF) { num = 0; char *ptr=strtok(str,"5"); while(ptr!=NULL) { string temp; len = strlen(ptr); for(i = 0; ptr[i] == '0'; ++i); if(i == len) ans[num++] = "0"; else { for(j = i; j < len; ++j) temp.push_back(ptr[j]); ans[num++] = temp; } ptr=strtok(NULL,"5"); } sort(ans, ans + num, cmp); for(int i = 0; i < num; ++i) cout<<ans[i]<<" "; cout<<endl; } return 0; }
相关文章推荐
- NYOJ 525-一道水题
- NYOJ525 一道水题
- NYOJ525 一道水题
- HDU 1106 NYOJ 525 排序 一道水题
- NYOJ 525 一道水题
- nyoj-525-一道水题
- nyoj 525 一道水题【字符串(分割)】
- NYOJ-525 一道水题
- nyoj-525-一道水题
- nyoj525 一道水题
- NYOJ 525 一道水题
- NYOJ 525--一道水题【水题(strtok)】
- NYOJ 525 一道水题
- nyoj525 一道水题
- nyoj 525 一道水题
- NYOJ1036 非洲小孩(又一道贪心水题,区间选点问题)
- nyoj 128 前缀式计算 模拟水题 回溯
- nyoj 一道水题
- nyoj 128 前缀式计算 模拟水题 回溯
- 水题NYOJ1071【不可以!】