**109-2 程式設計III 寒假作業**
344. Reverse String

```
void reverseString(char* s, int sSize){
int i,j;
char tem;
for(i=0,j=sSize-1;i<j;i++,j--){
tem=s[i];
s[i]=s[j];
s[j]=tem;
}
}
```
7. Reverse Integer


```
int reverse(int x){
long a=0;
while(x!=0){
a=a*10+x%10;
x=x/10;
}
if(a>=-INT_MAX &&a<=INT_MAX){
return a;
}
return 0;
}
```
13. Roman to Integer


```
int romanToInt(char * s)
{
int result = 0;
int i = -1;
while(s[++i])
{
if (s[i] == 'I')
result += 1;
else if (s[i] == 'V' && i != 0 && s[i-1] == 'I')
result += 3;
else if (s[i] == 'V')
result += 5;
else if (s[i] == 'X' && i != 0 && s[i-1] == 'I')
result += 8;
else if (s[i] == 'X')
result += 10;
else if (s[i] == 'L' && i != 0 && s[i-1] == 'X')
result += 30;
else if (s[i] == 'L')
result += 50;
else if (s[i] == 'C' && i != 0 && s[i-1] == 'X')
result += 80;
else if (s[i] == 'C')
result += 100;
else if (s[i] == 'D' && i != 0 && s[i-1] == 'C')
result += 300;
else if (s[i] == 'D')
result += 500;
else if (s[i] == 'M' && i != 0 && s[i-1] == 'C')
result += 800;
else if (s[i] == 'M')
result += 1000;
}
return result;
}
```
50. Pow(x, n)


```
double myPow(double x, int n){
double y;
y=pow(x,n);
return y;
}
```
268. Missing Number


```
int missingNumber(int* nums, int numsSize){
int sum = numsSize * (numsSize + 1) / 2;
int sum1 = 0;
for (int i = 0; i < numsSize; i++)
sum1 += nums[i];
return (sum - sum1);
}
```
509. Fibonacci Number


```
int fib(int n){
int num=0,num1=1,num2=0;
if(n==1){
return 1;
}
while(n-1>0){
num2=num+num1;
num=num1;
num1=num2;
n--;
}
return num2;
}
```
709. To Lower Case


```
char * toLowerCase(char * str){
for(int i=0;str[i]!='\0';i++){
if(str[i]>='A' && str[i]<='Z'){
str[i]+=32;
}
}
return str;
}
```
771. Jewels and Stones


```
int numJewelsInStones(char * J, char * S){
int s=0;int i,j;
for (i=0;i<strlen(J);i++){
for(j=0;j<strlen(S);j++){
if(J[i]==S[j])
s++;
}
}
return s;
}
```
905. Sort Array By Parity


```
int* sortArrayByParity(int* A, int ASize, int* returnSize){
int i=0,j=0,temp;
for(i=0;i<ASize-1;i++) {
for(j=i+1;j<ASize;j++){
if(A[i]%2!=0 && A[j]%2==0){
temp=A[i];
A[i]=A[j];
A[j]=temp;
}
}
}
*returnSize=ASize;
return A;
}
```
1137. N-th Tribonacci Number


```
int tribonacci(int n){
int a[38]={0,1,1};
int i=0;
for(i=3;i<=n;i++){
a[i]=a[i-1]+a[i-2]+a[i-3];
}
return a[n];
}
```
704. Binary Search


```
int tribonacci(int n){
int a[38]={0,1,1};
int i=0;
for(i=3;i<=n;i++){
a[i]=a[i-1]+a[i-2]+a[i-3];
}
return a[n];
}
```
1221. Split a String in Balanced Strings


```
int balancedStringSplit(char * s){
int n=0;
int answer=0;
for(int i=0;i<strlen(s);i++){
if(s[i]=='R'){
n++;
}
else if(s[i]=='L'){
n--;
}
if(n==0){
answer+=1;
}
}
return answer;
}
```
1678. Goal Parser Interpretation


```
char * interpret(char * command){
int len=strlen(command);
int a=0;
for(int i=0;i<strlen(command);){
if(command[i]=='G'){
command[a++]='G';
i++;
}
else if(command[i]=='(' && command[i+1]==')'){
command[a++]='o';
i+=2;
}
else{
command[a++]='a';
command[a++]='l';
i+=4;
}
}
command[a]='\0';
return command;
}
```
1512. Number of Good Pairs


```
int numIdenticalPairs(int* nums, int numsSize){
int degree=0;
for(int i=0;i<numsSize;i++){
for(int j=0;j<numsSize;j++){
if(nums[i]==nums[j] && i<j){
degree++;
}
}
}
return degree;
}
```
41. First Missing Positive


```
int firstMissingPositive(int* nums, int numsSize){
int min = 1;
int i=0;
while(i< numsSize){
if(nums[i] < 1){
i++;
continue;
}
if(nums[i] == min){
min++;
i=-1;
}
i++;
}
return min;
}
```