HDU 1062 Text Reverse
2016-01-25 21:28
465 查看
字符串反转:每个单词反转,然后输出。
PE做法:所有单词反转并写入另一个数组中,附代码
AC做法:每个单词写入数组并在空格时输出,考虑结束的情况,附代码
PE做法:所有单词反转并写入另一个数组中,附代码
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int N=1005; int main() { char ol ,no ; int n; // freopen("C:\\CODE\\in.txt", "r", stdin); // freopen("C:\\CODE\\out.txt","w",stdout); scanf("%d",&n); getchar(); while(n--) { gets(ol); for(int i=0,j=0; i<=strlen(ol); i++) { if(ol[i+1]==' '||i+1==strlen(ol)) { no[i+1]=ol[i+1]; for(int k1=i,k2=j; k1>=j; k2++,k1--) { no[k1]=ol[k2]; } j=i+2; } } puts(no); memset(no,0,sizeof(no)); } return 0; }
AC做法:每个单词写入数组并在空格时输出,考虑结束的情况,附代码
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int N=1005; int main() { char ol ,no ; int n; freopen("C:\\CODE\\in.txt", "r", stdin); //freopen("C:\\CODE\\out.txt","w",stdout); scanf("%d",&n); getchar(); while(n--) { gets(ol); for(int i=0,j=0; i<=strlen(ol); i++) { if(i == strlen(ol)){ while(j){ j--; printf("%c",no[j]); } } if(ol[i]!=' '){ no[j]=ol[i]; j++; } else{ while(j){ j--; printf("%c",no[j]); } printf(" "); } } putchar('\n'); } return 0; }
相关文章推荐
- js 横幅播放
- C++对象模型
- Codeforces Round #340 (Div. 2) D
- CLR Debug extention
- E 时间排序
- 字符串转化为整数的算法改进及优化
- song1
- 字符串转化为整数的算法改进及优化
- C#中的构造函数
- 获取指定日期时间的时间戳
- 如何让Android自适应不同分辨率或不同屏幕大小的layout布局
- [算法]旋转词问题
- iOS中多控制器的使用
- 蒙特卡洛-马尔科夫链(MCMC)初步
- 框框架架
- 动态规划的基本概念和基本模型构成
- three2
- 1049. Counting Ones/整数中1出现的次数(从1到n整数中1出现的次数)
- cv::Mat 图像矩阵操作
- 【YouXue 1019】鹿死谁手