Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<string.h>
- bool checkPalindrome(char str[])
- {
- int i=0,j=strlen(str)-1;
- while(j>i)
- {
- if(str[i]!=str[j])
- return false;
- i++;
- j--;
- }
- return true;
- }
- #include<string.h>
- void replaceCharacter(char input[], char c1, char c2) {
- int i=0;
- int j = strlen(input);
- for(i; i < j;i++){
- if(input[i] == c1){
- input[i]=c2;
- }
- }
- }
- #include<string.h>
- void trimSpaces(char input[]) {
- int count = 0;
- int len = strlen(input);
- for(int i = 0; input[i]; i++){
- if(input[i] != ' '){
- input[count]=input[i];
- count++;
- }
- }
- input[count] = '\0';
- }
- int length(char input[])
- {
- int len = 0;
- for(int i = 0; input[i] != '\0'; i++)
- {
- len++;
- }
- return len;
- }
- void reverse(char input[], int start, int end){
- int i = start,
- j = end;
- while(i < j)
- {
- char temp = input[i];
- input[i] = input[j];
- input[j] = temp;
- i++;
- j--;
- }
- }
- void reverseCompleteString(char input[]) {
- int i = 0,
- j = length(input) - 1;
- while(i < j) {
- char temp = input[i];
- input[i] = input[j];
- input[j] = temp;
- i++;
- j--;
- }
- }
- void reverseStringWordWise(char input[]){
- reverseCompleteString(input);
- int start = 0,
- end = 0, i;
- for(i = 0; input[i] != '\0'; i++){
- if(input[i] == ' '){
- end = i - 1;
- reverse(input, start, end);
- start = i + 1;
- }
- }
- end = i - 1;
- reverse(input, start, end);
- }
- #include<cstring>
- void printSubstrings(char str[]){
- for(int start = 0; str[start] != '\0'; start++){
- for(int end = start; str[end] != '\0'; end++){
- for(int i = start; i <= end; i++){
- cout << str[i];
- }
- cout << endl;
- }
- }
- }
- #include<iostream>
- using namespace std;
- int main(){
- int row, col;
- cin>>row>>col;
- int arr[row][col];
- for(int i = 0; i < row; i++){
- for(int j = 0; j < col; j++ ){
- cin>>arr[i][j];
- }
- }
- int j = 0;
- while(j < col){
- int i = 0;
- int col1 = 0;
- for(i; i < row; i++){
- col1 = col1 +arr[i][j];
- }
- j++;
- cout<< col1 << " ";
- }
- }
- #include<climits>
- void findLargest(int **input, int nRows, int mCols){
- int i,j,sum = 0;
- int tempr = INT_MIN;
- int maxrow = 0, maxr = 0;
- // finding each nRows sum
- for(i = 0; i < nRows; i++){
- for (j = 0; j < mCols; j++) {
- // Add the element
- sum = sum + input[i][j];
- }
- //finding th greatest nRows
- if(sum > tempr){
- maxrow = sum;
- maxr = i;
- tempr = maxrow;
- }
- // Reset the sum
- sum = 0;
- }
- i=0,j=0,sum = 0;
- int tempc = INT_MIN;
- int maxcol = 0, maxc = 0;
- // finding the each mColsumn sum
- for (i = 0; i < mCols; ++i) {
- for (j = 0; j < nRows; ++j) {
- // Add the element
- sum = sum + input[j][i];
- }
- // finding th greatest mColsumn
- if(sum > tempc){
- maxcol = sum;
- maxc = i;
- tempc = maxcol;
- }
- // Reset the sum
- sum = 0;
- }
- //comparing the max nRows or mCols
- if(maxrow > maxcol){
- cout<<"row " << maxr<<" "<<maxrow;
- }
- else if(maxrow < maxcol){
- cout<<"column " << maxc<<" "<<maxcol;
- }
- else{
- cout<<"row " << maxr<<" "<<maxrow;
- }
- }
- #include <iostream>
- using namespace std;
- void wavePrint(int **input, int nRows, int mCols){
- for(int i = 0 ;i < mCols; i++)
- {
- if(i % 2 == 0)
- {
- for(int j = 0; j < nRows; j++)
- {
- cout << input[j][i] << " ";
- }
- }
- else
- {
- for(int j = nRows - 1; j >= 0; j--)
- {
- cout << input[j][i] << " ";
- }
- }
- }
- }
- #include <iostream>
- using namespace std;
- void spiralPrint(int **input, int nRows, int nCols){
- int i, k = 0, l = 0;
- while (k < nRows && l < nCols) {
- for (i = l; i < nCols; i++) {
- cout << input[k][i] << " ";
- }
- k++;
- for (i = k; i < nRows; i++) {
- cout << input[i][nCols - 1] << " ";
- }
- nCols--;
- if (k < nRows){
- for (i = nCols - 1; i >= l; i--) {
- cout << input[nRows - 1][i] << " ";
- }
- nRows--;
- }
- if (l < nCols){
- for (i = nRows - 1; i >= k; i--) {
- cout << input[i][l] << " ";
- }
- l++;
- }
- }
- }
- bool isPermutation(char input1[], char input2[]) {
- int freq[256] = {0};
- for(int i = 0; input1[i] != '\0'; i++) {
- int index = input1[i];
- freq[index]++;
- }
- for(int i = 0; input2[i] != '\0'; i++) {
- int index = input2[i];
- freq[index]--;
- }
- for(int i = 0; i < 256; i++) {
- if(freq[i] != 0) {
- return false;
- }
- }
- return true;
- }
- void removeConsecutiveDuplicates(char input[]) {
- int nextIndex = 1;
- char lastChar = input[0];
- for(int i = 0; input[i] != '\0';) {
- if(input[i] == lastChar) {
- i++;
- }
- else {
- input[nextIndex] = input[i];
- nextIndex++;
- lastChar = input[i];
- i++;
- }
- }
- input[nextIndex] = '\0';
- }
- void reverse(char input[], int start, int end){
- int i = start, j = end;
- while(i < j){
- char temp = input[i];
- input[i] = input[j];
- input[j] = temp;
- i++;
- j--;
- }
- }
- void reverseEachWord(char input[]){
- int start = 0, end = 0, i;
- for(i = 0; input[i] != '\0'; i++){
- if(input[i] == ' '){
- end = i - 1;
- reverse(input, start, end);
- start = i + 1;
- }
- }
- end = i - 1;
- reverse(input, start, end);
- }
- #include<cstring>
- void removeAllOccurrencesOfChar(char input[], char c) {
- // Write your code here
- int j, n = strlen(input);
- for (int i=j=0; i<n; i++)
- if (input[i] != c)
- input[j++] = input[i];
- input[j] = '\0';
- }
- #include<bits/stdc++.h>
- #define ASCII_SIZE 256
- // input - given string
- char highestOccurringChar(char str[]) {
- char result;
- int i, len;
- int max = -1;
- int freq[256] = {0};
- len = strlen(str);
- for(i = 0; i < len; i++)
- {
- freq[str[i]]++;
- }
- for(i = 0; i < len; i++)
- {
- if(max < freq[str[i]])
- {
- max = freq[str[i]];
- result = str[i];
- }
- }
- return result;
- }
- string getCompressedString(string &input) {
- int count = 1;
- char currentChar = input[0];
- int i, nextIndex = 1;
- for(i = 1; input[i] != '\0'; i++){
- // Count the occurrence of consecutive duplicate character
- if(input[i] == currentChar){
- count++;
- }
- else{
- // Append the count with string
- if(count > 1){
- input[nextIndex] = char(count + 48);
- nextIndex++;
- }
- currentChar = input[i];
- input[nextIndex] = input[i];
- nextIndex++; count = 1;
- }
- }
- if(count > 1){
- input[nextIndex] = char(count + 48);
- nextIndex++;
- }input[nextIndex] = '\0';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement