Repository navigation
Expand file tree
/
Copy pathstring.cpp
More file actions
536 lines (483 loc) · 11.1 KB
/
Copy pathstring.cpp
File metadata and controls
536 lines (483 loc) · 11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
// int main(){
// string s;
// getline(cin,s);
// string s1;
// getline(cin,s1);
//cout<<s.length()<<s1.size(); // hello world ans 5 5//start with 1
//s.resize(2);
//s1.resize(3);
//cout<<s<<s1;//hello world ans he wor
//s.resize(10);
//cout<<s.length();//ans is 10
// s.resize(7,'@');
// cout<<s;//hello ans hello@@
// s.resize(2,'*');
// cout<<s; //hello ans he
//if you dont know the length of the string then you
//can do this
//s.resize(s.length()+2,'#')// hello ans hello##
//cout<<s.at(2); //hello ans 01233 ans is l
//if you want to chage some charactor then you can
// s.at(1)='N';//start with 0
// cout<<s;//hello == hNllo ans
// s.at(10)='Y';
// cout<<s;//input is hello //its out of the range it terminate and return std::out_of_range
// s+=s1;
// cout<<s;//hello world == hellowordl
//cout<<s.substr(6,5);//start with 123456tel ans is tel
// cout<<s.substr(6);
// cout<<s.find(s1); //i/o=abc abc abc ab 0 // if can not find then return std::string::npos
//starting with 0 // return first occurance position
// cout<<s.find(s1,3);//check after 3 position and return first occurance
//}
// int main(){//this is use to input more and more this while# is not encounter
// string s,s1;
// do{
// getline(cin,s);
// s1+=" ";
// s1+=s;
// }
// while(s!="#");
// cout<<s1;
// }
// int main(){//use to remove charactore .. input helloaaa nehaa
// //output hello neh
// int i;
// string s,s1;
// getline(cin,s);
// for(i=0;i<s.length();i++){
// if(s.at(i)!='a')
// s1+=s.at(i);
// }
// cout<<s1;
// }
// int main(){
// int n,i;
// int flag;
// cin>>n;
// if(n==0 || n==1)
// flag=1;
// else{
// for(int i=2;i<=sqrt(n);i++){
// if(n%i==0)
// flag=0;
// break;
// }
// }
// if(flag)
// cout<<" prime";
// else
// cout<<"not prime";
// }
// int main(){
// string s;
// int p;
// getline(cin,s);
// string s1;
// getline(cin,s);
// int l=s.length();
// do{
// p=s.find(s1);
// cout<<p;
// l--;
// }
// while(l>0 && p!=string::npos);
// }
#include <iostream>
#include <string>
using namespace std;
// int main() { use to find substr position in string input - abc abc abc abc
//output
// ab
// 0
// 4
// 8
// 12
// string s;
// getline(cin, s);
// string s1;
// getline(cin, s1);
// if (s1.empty()) {
// cout << "Error: input string is empty." << endl;
// return 1;
// }
// int l = s.length();
// int p=-1;
// do {
// p = s.find(s1,p+1);
// if(p!=-1)
// cout << p << endl;
// } while (p != string::npos);
// return 0;
// }
// int main(){ // to count how many time substr is present //i-o abc abc abc abc
// // a
// // 4
// string s;
// getline(cin,s);
// string s1;
// getline(cin,s1);
// int p=-1;
// int x=0;
// do{
// p=s.find(s1,p+1);
// if(p!=-1)
// x++;
// }
// while(p!=-1);
// cout<<x;
// }
//if you want to convert all letter in upper or lower case then do this
// for(i=0;i<s.length();i++)
// s.at(i)+32 or s.at(i)-32;
// int main(){//one two three // output - one two zero three
// string s;
// getline(cin,s);
// string s1;
// getline(cin,s1);
// int p=-1;
// int l;
// do{
// p=s.find(" ",p+1);
// if(p!=-1)
// l=p;
// }
// while(p!=-1);
// cout<<s.substr(0,l)+s1+s.substr(l,s.length());
// }
// int main(){ // remove some words // i love my life you are my hello my friend
// // i love life you are hello friend
// string s;
// getline(cin,s);
// string s1;
// getline(cin,s1);
// int p=-1;
// //int l;
// do{
// p=s.find(s1,p+1);
// if(p!=-1)
// s=s.substr(0,p)+s.substr(p+s1.length());
// }
// while(p!=-1);
// cout<<s;
// }
// int main(){// replace wwords
// //input// i love my life you are my hello my frined
// // my
// // your
// //out// i love your life you are your hello your frined
// string s;
// getline(cin,s);
// string s1;
// getline(cin,s1);
// string s2;
// getline(cin,s2);
// int p=-1;
// int l;
// do{
// p=s.find(s1,p+1);
// if(p!=-1)
// s=s.substr(0,p)+s2+s.substr(p+s1.length());
// }
// while(p!=-1);
// cout<<s;
// }
/* so IMPORTTANT */
// Here's a list of string functions in C++ and whether they start counting from 0 or 1:
// Counting from 0:
// find()
// rfind()
// find_first_of()
// find_last_of()
//rfind()= find from the last
// find_first_not_of()
// find_last_not_of()
// substr()
// replace()
// erase()
// insert()
// push_back()
// Counting from 1:
// length()
// size()
// max_size() // depends upon compiler
// capacity()
// resize()
// reserve()
// clear()
// empty() // return boolean
// compare()
// swap()
// int main(){ // how to creat string object
// string s1;
// getline(cin,s1);//allow space
// string s2("abc hello ");
// string s3;
// cin>>s3;// terminate after space
// cout<< s1<< s2<< s3;
// }
// int main(){
// string s1;
// getline(cin,s1);
// cout<<s1.capacity();
// }
// int main(){
// string s2;
// getline(cin,s2);
// string s1;
// getline(cin,s1);
// if(s1==s2)
// cout<<"equal";
// else if(s1>s2)
// cout<<"s1 greter" ;
// else
// cout<<"s2 greter";
// //cout<<s1>s2;
// cout<<s1.compare(s2);
// }
// int main(){
// string s;
// getline(cin,s);
// string s1;
// getline(cin,s1);
// cout<<s.replace(4,1,"/")<<endl; // hello neha hello prit == hell/ neha
// cout<<s.erase(5)<<endl; //==hell/
// cout<<s1.insert(10,s)<<endl; //hello prithell/
// int x=s.compare(0,s1.size(),s1); //o>/ return -1;
// cout<<x<<endl;
// s1=s.substr(5,3);//hell/ have only 5 charactore so return null
// cout<<s1;
// }
//################################################################
//in summary, max_size() returns the theoretical maximum size that a container can reach, while capacity() returns the current storage capacity of the container.
// int main(){
// string s("hello nehss ?1");
// cout<<s.capacity();
// s.pop_back(); // delete last charactore of the given string
// cout<<s;
// cout<<s.capacity()<<'\n';
// s.resize(10);
// cout<<s.capacity()<<"\n";
// s.shrink_to_fit();
// cout<<s.capacity()<<'\n';
// }
// int main(){
// string s("ABCD");
// cout<<s.capacity();
// s.reserve(20);
// cout<<s.capacity();
// s.resize(3);
// cout<<s.capacity();
// s.shrink_to_fit();
// cout<<s.capacity();
// s.reserve(40);
// cout<<s.capacity();
// }
// output
// 15
// 30
// 30
// 15
// 40
// int main(){
// string s1("123");
// int s=0;
// for(int i=0;i<s1.length();i++){
// s=s+s1.at(i);
// }
// s=s-48*s1.length();
// cout<<s<<"\n";
// }
// int main(){ // if reverce string then prit yes to behave like strrev
// string s;
// cin>>s;
// for(int i=0;i<s.length()/2;i++){
// if(s.at(i)!=s.at(s.length()-i-1)){
// cout<<"no"<<"\n";
// break;
// }
// else
// cout<<"yes";
// }
// }
// int main(){ //use to convert in upper case
// string s;
// char r[2];
// cin>>s;
// for(int i=0;i<s.length();i++){
// char ch=s.at(i);
// if(ch>=97 && ch<=122){
// r[0]=ch-32;
// s.replace(i,1,string(r));
// }
// }
// cout<<s<<"\n";
// }
// int main(){ // use like caser ciopher
// // hello
// // IFMMP // increment by 1 also in upper
// string s;
// char r[2];
// r[1]='\0';
// cin>>s;
// for(int i=0;i<s.length();i++){
// if(isalpha(s.at(i))){
// r[0]=toupper(s.at(i)=='Z'?'A':toupper(s.at(i))+1);
// s.replace(i,1,string(r));
// }
// }
// cout<<s<<flush;
// }
// int main(){
// string s1("we love to walk");
// if(s1.at(4)==s1[4]){
// s1=s1.substr(8,7);
// cout<<s1;
// }
// else
// s1.replace(7,4,"hate");
// }
//###########################################################################
//1
// int main(){
// string s,s1,s2;
// cin>>s>>s1>>s2;
// string s3;
// s3=s+" "+s1+" "+s2;
// cout<<s3;
// string s4;
// s4.append(s);
// s4.append(" ");
// s4.append(s1);
// s4.append(" ");
// s4.append(s2);
// cout<<s4;
// }
//2
// int main(){
// string s;
// getline(cin,s);
// int i=0;
// while((s.length())!=i){
// cout<<s.at(i);
// i++;
// }
// }
//3
// int main(){
// int n;
// cin>>n;
// string s;
// while(n!=0){
// cin>>s;
// n--;
// if(s.at(0)=='B' || s.at(0)=='C')
// cout<<s;
// }
// }
//4
// int main(){
// string s;
// getline(cin,s);
// int p=-1;
// do{
// p=s.find(" ",p+1);
// if(p!=-1)
// s.replace(p,1,"_");
// }
// while(p!=-1);
// cout<<s;
// }
//5
// int main(){
// string s;
// getline(cin,s);
// int p=-1;
// int c=0;
// do{
// p=s.find('e',p+1);
// if(p!=-1)
// c++;
// }
// while(p!=-1);
// cout<<c;
// }
//6
// int main(){
// string s;
// getline(cin,s);
// int p=-1;
// int c=0;
// do{
// p=s.find("It",p+1);
// if(p!=-1)
// c++;
// }
// while(p!=-1);
// cout<<c;
// }
//7
// #include <iostream>
// #include <vector>
// #include <algorithm>
// using namespace std;
// bool compare(string a,string b){
// return a<b;
// }
// int main(){
// int n;
// cin>>n;
// int i,j;
// vector<string> y;
// string s;
// cin.ignore();
// for(i=0;i<n;i++){
// getline(cin,s);
// y.push_back(s);
// }
// sort(y.begin(),y.end(),compare);
// for(i=0;i<n;i++){
// cout<<y[i]<<endl;
// }
// return 0;
// }
// 1
// 2 3 2
// 3 4 5 4 3
// 4 5 67 6 5 4
// #include <iostream>
// #include <string>
// using namespace std;
// int main() {
// string s = "123456";
// int n = s.size();
// int width = (n - 1) * 2 + 1;
// for (int i = 0; i < n; i++) {
// // print leading spaces
// for (int j = 0; j < (width - (i * 2 + 1)) / 2; j++) {
// cout << " ";
// }
// // print left half
// for (int j = 0; j <= i; j++) {
// cout << s[j] << " ";
// }
// // print right half
// for (int j = i - 1; j >= 0; j--) {
// cout << s[j] << " ";
// }
// // print trailing spaces
// for (int j = 0; j < (width - (i * 2 + 1)) / 2; j++) {
// cout << " ";
// }
// // print newline
// cout << endl;
// }
// return 0;
// }