关于vector的习题(三)
来源:互联网 发布:大数据魔镜官网 编辑:程序博客网 时间:2024/04/28 00:53
庭博网校原创 QQ14280784 86974558
大专以上学历,2500元一年;高中毕业,3000元一年;初中毕业:3500元一年。是学费哦!
/*
读入一段文本到vector对象,每个单词存储为vector中的一个元素。
把vector对象中每个单词转化为大写字母。输出vector对象中转化后
的元素,每八个单词为一行输出。
*/
#include "iostream"
#include "vector"
#include "string"
using namespace std;
int main()
{
vector<string> text;
string str;
while(cin>>str)
text.push_back(str);
fflush(stdin);
vector<string>::size_type x1;
string::size_type x2;
for(x1=0;x1!=text.size();x1++)
{
for(x2=0;x2!=text[x1].size();x2++)
text[x1][x2]=toupper(text[x1][x2]);
}
for(x1=0;x1!=text.size();x1++)
{
if(x1%8==0 && x1!=0)
{
cout<<endl;
cout<<text[x1];
}
else cout<<text[x1];
}
getchar();
return 0;
}
//===============================================================================
以下是用迭代器去实现
/*
读入一段文本到vector对象,每个单词存储为vector中的一个元素。
把vector对象中每个单词转化为大写字母。输出vector对象中转化后的
元素,每八个单词为一行输出。要求用迭代器实现
*/
#include "iostream"
#include "vector"
#include "string"
using namespace std;
int main()
{
vector<string> a;
string s1;
while(cin>>s1)
a.push_back(s1);
fflush(stdin);
vector<string>::iterator i;
int x;
for(x=0,i=a.begin();i<a.end();i++,x++)
{
if(x%8==0 && x!=0)
{
cout<<endl;
cout<<*i<<" ";
}
else cout<<*i<<" ";
}
getchar();
return 0;
}
- 关于vector的习题(三)
- 关于vector的习题(一)
- 关于vector的习题(二)
- vector操作的习题
- STL之vector的使用三(vector的删除)
- 可爱的python课后习题(三)
- 习题三(1)
- 习题三(2)
- 关于集合的习题(1)
- 关于集合的习题(3)
- 关于类的习题
- 关于栈的习题
- STL(三):vector
- 关于vector的一些问题(5.11)
- 关于vector性能的测试(一)
- 关于vector的使用
- 关于vector的vector<vector<int>>的使用问题
- Java 作业 习题2 关于日期的三道编程题
- 编译HTC desire S CM的代码
- 如何写论文
- 3.指针
- The centre of polygon (多边形重心)
- 相关算法资源
- 关于vector的习题(三)
- 推荐系统 机器学习的blog
- 理解ext4,第一部分(extents)
- different object with the same identifier value was already associated with the sessi(一对多映射和多对多映射中)
- PV原语
- 和音乐有关
- 膝关节韧带重建手术日记
- ubuntu11.10配置Lamp
- word骨灰级水平,赶紧留一份