0% found this document useful (0 votes)
3 views

string

Uploaded by

locnt1286
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

string

Uploaded by

locnt1286
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <iostream>

#include<vector>
#include <algorithm>
using namespace std;

void xuatMang(vector<int> a){


for (auto it : a){
cout<<it<<" ";
}
}
int finded(vector<int> a, int n, int x){
int l=0,r=n-1;
while(l<=r){
int m=(l+r)/2;
if(a[m]==x){
return 1;
}else if(a[m]<x){
l=m+1;
}else{
r=m-1;
}
}
return 0;
}

int main()
{
int n,b,c=1,x;
vector<int> a;
cin>>n;
cin>>x;
for( int i=0; i<n; i++){
cin>>b;
a.push_back(b);
}
for( int i=1; i<n; i++){
int x=a[i],pos=i-1;
while(pos>=0&&a[pos]>x){
a[pos+1]=a[pos];
pos--;
}
a[pos+1]=x;
}
cout<<finded(a,n,x)<<endl;
xuatMang(a);
return 0;
}

#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

void removedSpace(string s){


stringstream ss(s);
string token;
while(ss>>token){
if(token != " "){
cout<<token<<" ";
}
}
}

void count(string s){


int a=0;
stringstream ss(s);
string token;
while(ss>>token){
++a;
}
cout<<a;
}

void longestWord(string s){


int a=0;
stringstream ss(s);
string token;
string b;
while(ss>>token){
if(token.length()>a){
a=token.length();
b=token;
}
}
cout<<b;
}

void inital(string s){


vector<string> a;
stringstream ss(s);
string token;
while(ss>>token){
a.push_back(token);
}
for(int i=0; i<a.size(); i++){
a[i][0]=toupper(a[i][0]);
}
for( auto it : a){
cout<<it<<" ";
}
}

void swaped(string s){


stringstream ss(s);
string token;
string a,b;
cin>>a>>b;
while(ss>>token){
if(token == a){
token=b;
}
cout<<token<<" ";
}
}
int main() {
int n;
string s;
getline(cin,s);
cin>>n;
switch (n){
case 1: removedSpace(s);break;
case 2: count(s);break;
case 3: longestWord(s);break;
case 4: inital(s);break;
case 5: swaped(s);
}

return 0;
}

You might also like