JXNVCE ALGO-LOG YouJin Jung

BOJ-1306

#include <iostream>

using namespace std;

int main() {	
	int n;
	int cnt = 0;
	string str;
	cin >> n;

	for(int i=0; i<n; i++){
		cin >> str;
		int size = str.length();
		bool flag = true;
		
		for(int j=0; j<size; j++){
			for(int k=0; k<j; k++){
				if(str[j] != str[j-1] && str[j] == str[k]){
					flag = false;
					break;			
				}				
			}
		}
		if(flag) cnt++;
	}
	
	cout << cnt;

    return 0;
}

BOJ- 1966

#include <iostream>
#include <queue>

using namespace std;

int main() {
    int count=0;
    int input;
    cin >> input;
    int n, m, c
    for (int i=0; i<input; i++) {
        count = 0;
        cin >> n >> m;
        queue<pair<int, int>> q;
        priority_queue<int> pq;
        for (int j=0; j < n; j++) {
            cin >> c;
            q.push({j,c});
            pq.push(c);
        }
        while (!q.empty()) {
            int index = q.front().first;
            int value = q.front().second;
            q.pop();
            if (pq.top() == value) {
                pq.pop();
                ++count;
                if (index == m) {
                    cout << count << endl;
                    break;
                }
            }
            else q.push({ index,value });
        }
    }

CODERBYTE STRING CHALLENGE

#include <iostream>
#include <string>
#include <queue>
#include <utility>
#include <math.h>
#include <sstream>
using namespace std;

int getQNum(queue<pair<string, int>> q) {
  int qsize = q.size();
  int num = q.front().second;
  for (int i=qsize; i>0; i--) {
    int dnum = q.front().second * pow(10, i-1);
    q.pop();
    if (q.empty()) break;
    num = dnum + q.front().second;
  }
  return num;
}

int getNqNum(queue<int> nq) {
  int num = nq.front();
  int size = nq.size();
  for (int i=size; i>0; i--) {
    int dnum = nq.front() * pow(10, i-1);
    nq.pop();
    if (nq.empty()) break;
    num = dnum + nq.front();
  }
  return num;
}

int NumDigits(int x) {  
    x = abs(x);  
    return (x < 10 ? 1 :   
        (x < 100 ? 2 :   
        (x < 1000 ? 3 :   
        (x < 10000 ? 4 :   
        (x < 100000 ? 5 :   
        (x < 1000000 ? 6 :   
        (x < 10000000 ? 7 :  
        (x < 100000000 ? 8 :  
        (x < 1000000000 ? 9 :  
        10)))))))));  
}

void StringChallenge(string str) {
  queue<pair<string, int>> q;
  queue<int> nq;
  string listNum[12] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "plus", "minus"};
  string word;
  int num = 0;
  int resultNum;
  string result;
  for (int i=0; i<str.length(); i++) {
    word.push_back(str[i]);
    for (int j=0; j<12; j++) {
      if (/*!word.compare(listNum[i])*/word==listNum[j]) {
        q.push(make_pair(word, j));
        word = "";
        break;
      }
    }
  }
  while (!q.empty()) {
    if (q.front().second == 10 || q.front().second == 11) {   
      num = getNqNum(nq);
      if (q.front().second == 10) {
        q.pop();
        int temp = getQNum(q);
        resultNum = num + temp;
      }
      else {
        q.pop();
        int temp = getQNum(q);
        resultNum = num - temp;
      }
    }
    else {
      nq.push(q.front().second);
    }
    q.pop();
  }

  int digit = NumDigits(resultNum);
  word = "";
  ostringstream os;
  os << resultNum;
  string digits = os.str();
  if (digits[0]=='-') digit++;
  for (int i=0; i<digit; i++) {
    if (digits[i]=='-') cout << "negative";
    else {
      int s = stoi(string(1, digits[i]));
      cout << listNum[s];
    }
  }
}

int main(void) { 
  // keep this function call here
  StringChallenge(coderbyteInternalStdinFunction(stdin));
  return 0;
    
}

GFG-LONGEST-COMMON-SEQUENCE

DP 기초 공부를 위한 예제, LCS!

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

int max(int a, int b) {
    return (a > b)? a : b;
}

int lcs( char *X, char *Y, int m, int n ) {
    if (m == 0 || n == 0)
        return 0;
    if (X[m-1] == Y[n-1])
        return 1 + lcs(X, Y, m-1, n-1);
    else
        return max(lcs(X, Y, m, n-1), lcs(X, Y, m-1, n));
}

int main() {
    char X[] = "AGGTAB";
    char Y[] = "GXTXAYB";
     
    int m = strlen(X);
    int n = strlen(Y);
     
    cout<< "Length of LCS is "<< lcs( X, Y, m, n );
     
    return 0;
}

GFG LONGEST REPEATED SUBSEQUENCE

DP practice set from Geeks for Geeks

int findLongestRepeatingSubSeq(string str)
{
    int n = str.length();
  
    // Create and initialize DP table
    int dp[n+1][n+1];
  //initializing first row and column in dp table
    for(int i=0;i<=n;i++){
      dp[i][0] =0;
      dp[0][i] =0;
    }
   
  
    // Fill dp table (similar to LCS loops)
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
        {
            // If characters match and indexes are
            // not same
            if (str[i-1] == str[j-1] && i != j)
                dp[i][j] =  1 + dp[i-1][j-1];         
                       
            // If characters do not match
            else
                dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
        }
    }
    return dp[n][n];
}