字符串-05~~~07

字符串-05

#include<iostream>
int main()
{
using namespace std;
char line[30];
int move;
cout << "Enter some words and move scale:\n";
cin.get(line, 30);
cin >> move;
char *t=new char[30];
int n = strlen(line);
for (int i = 0; i < n; i++)
{
if (i < move)
t[n - move + i] = line[i];
else
t[i - move] = line[i];
}
for (int i = 0; i < n; i++)
cout << t[i];
delete[] t;
return 0;
}


字符串-06

#include<iostream>
#include<cmath>
int main()
{
char line[33]; //这里的line[]是char类型
int lint[32] = {0};
using namespace std;
std::cout << "Enter 8 0-1 value:";
cin.get(line, 33);
int result[4] = {0};
for (int i = 0; i < 32; i++)
{
lint[i] = int(line[i]) - 48;
result[i / 8] += lint[i]* pow(2, (31-i) % 8);
}
cout << endl;
for (int i = 0; i < 3; i++)
cout << result[i] <<".";
cout << result[3];
return 0;
}


字符串-07

#include<iostream>

#include<string>
#include<vector>
#include<algorithm>
using namespace std;
void show(const string &s);
int main()
{
vector<string>line;
string temp;
cout << "Enter you words(quit to quit) :\n";
while (cin>>temp&&temp!="quit")
{
line.push_back(temp);
}
for_each(line.rbegin(), line.rend(), show);
return 0;
}
void show(const string &s)
{
cout << s << ' ';
}
阅读更多
文章标签: PAT
上一篇7.7
下一篇循环-01~~~05
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭