int T, i;
scanf("%d", &T);
char a[T], b[T], c[T];
int temp[T], temp2[T], temp3[T];
int point1[T], point2[T], point3[T];
for(i=0;i<T; i++){
scanf("%c %c %c", &a[i], &b[i], &c[i]);
switch(a[i]){
case '!':
point1[i] = 5;
break;
case '%':
point1[i] = 4;
break;
case '&':
point1[i] = 3;
break;
case '^':
point1[i] = 2;
break;
case '|':
point1[i] = 1;
break;
default :
point1[i]=10;
}
switch(b[i]){
case '!':
point2[i] = 5;
break;
case '%':
point2[i] = 4;
break;
case '&':
point2[i] = 3;
break;
case '^':
point2[i] =2;
break;
case '|':
point2[i] =1;
break;
default :
point2[i]=10;
}
switch(c[i]){
case '!':
point3[i] = 5;
break;
case '%':
point3[i] = 4;
break;
case '&':
point3[i] = 3;
break;
case '^':
point3[i] =2;
break;
case '|':
point3[i] =1;
break;
default :
point3[i]=10;
}
if(point1[i]<point2[i]) {
temp[i]=point1[i];
point1[i]=point2[i];
point2[i]=temp[i];
}
if(point1[i]<point3[i]){
temp2[i]=point1[i];
point1[i]=point3[i];
point3[i]=temp2[i];
}
if(point2[i]<point3[i]){
temp3[i]=point2[i];
point2[i]=point3[i];
point3[i]=temp3[i];
}
printf("%d %d %d\n", point1[i], point2[i], point3[i]);
}
return 0;
So first of all, i was asked to input certain characters randomly arranged and make them printed arranged from the highest precedence.
The precedence of the operators (from the highest to the lowest) are "!" (logical NOT), "%" (remainder), "&"
(bitwise AND), "^" (bitwise XOR), , "|" (bitwise OR).
So i try to change the characters into numbers and try to arrange the number first then change the number again to the characters.
But when i try to check if the numbers have been correctly arranged, it's not.
Any idea what's wrong with my code?
Or any idea to make my code simpler without having to turn the characters into numbers?
Here's the sample
Sample Input
3
& ^ %
& ^ !
& ^ !
Sampe Output
Case #1: % & ^
Case #2: ! & ^
Case #3: ! & ^
A few issues have already been noted in the comments. Specifically, scanf leaves the trailing newline in the input buffer. You can fix that using the suggestion by #4386427.
You can avoid manually assigning numbers for each character by noting that their ASCII is already in required order. That is, '!' < '%' < '&' < '^' < '|'. So you can simply read them into a char array of the appropriate size and just sort them in ascending order before printing the char array. This will significantly shorten and clean up your code.
#include <stdio.h>
#include <stdlib.h>
int cmpfunc (const void * a, const void * b) {
return (*((char*)a) > *((char*)b)) - (*((char*)a) < *((char*)b));
}
int main(int argc, char *argv[])
{
int T, i, j;
scanf(" %d", &T);
/* TODO: Check if number of chars per line is T or 3. */
char *a = malloc(T * sizeof(char));
for(i = 0; i < T; i++) {
for (j = 0; j < T; j++) {
scanf(" %c", &a[j]);
}
printf("Before sort\n");
for (j = 0; j < T; j++) {
printf("%c ", a[j]);
}
printf("\n");
qsort(a, T, sizeof(a[0]), cmpfunc);
printf("After sort\n");
for (j = 0; j < T; j++) {
printf("%c ", a[j]);
}
printf("\n");
}
free(a);
return 0;
}
Related
Given an integer n, the program has to delete each word, that contains the n number of vowels.
The string is read from a test.txt file, which contains the following:
Astazi nu este maine.
Currently my program contains a count1 function, that counts the number of characters and vowels for each word in the string.
How can I use the data from count1 function as a refference when typing in the n vowels to delete the needed words then print the updated string?
I have an idea, which I'm unsure how to implement. In count1 we already count the number of vowels per each word, so, given n by the user we check if this number is equal to v in the count1 function and so we do int num_of_words++, then we do a loop, which prints out the needed words, until num_of_words=0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
void count1 (char* str)
{
for (int i = 0;;)
for (int v = 0, w = i;;)
{
int len;
char c = str[i++];
switch (c)
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
v++;
default:
continue;
case ' ':
case '\t':
case '\n':
case '\0':
len = i - 1 - w;
printf("'%.*s': %d characters, %d vowels\n", len, str+w, len, v );
if (c)
break;
else
return;
}
break;
}
}
void count2 (char* str, int n)
{
char line2[128];
int ls=strlen(str);
for (int i = 0;;)
for (int v = 0, w = i;;)
{
int len;
char c = str[i++];
switch (c)
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
v++;
default:
continue;
case ' ':
case '\t':
case '\n':
case '\0':
for(int k = 0; str[k] != '\0'; k++)
{
if (k == 0 || isspace(str[k]))
{
if(v==n)
{
strcat(line2, str+1);
}
}
}
printf("%s ", line2);
if (c)
break;
else
return;
}
break;
}
}
int main()
{
FILE *fp;
char line[128];
int c=0, count[26]= {0}, x;
int n;
fp = fopen("test.txt", "r");
fscanf(fp, "%[^\n]", line);
fclose(fp);
printf("%s\n\n", line);
while (line[c] != '\0')
{
if (line[c] >= 'a' && line[c] <= 'z')
{
x = line[c] - 'a';
count[x]++;
}
c++;
}
for (c = 0; c < 26; c++)
{
printf("%c occurs %d times.\n", c + 'a', count[c]);
}
printf("\n");
count1(line);
printf("\nInsert n: ");
scanf("%d", &n);
count2(line, n);
return 0;
}
If you have a string str that consists of separate words, separated one from another by ' ' or '\n' or '\t', and you want to have a string that contains all the words in str that satisfy some condition, it will be a bit difficult to program it such that it will be "in-place", i.e. to change str to the desired string, without using a "helper array" of some sort.
Instead, I would recommend to create a new char array with the same size (say str2), and every time you find a word that satisfies the condition (the condition can be for example: doesn't have 1 vowel), you copy the word that you found from str to str2.
Something like this:
char str[128];
// read from file to str using fscanf
char str2[128];
for (int c = 0; str[c] != '\0'; ++c)
{
if (c == 0 || isspace(str[c]))
{
if (! is_1_vowel[str+1]) // if it doesn't have exacly one vowel
{
// copy the word from str to str2
strcat_word(str2, str+1); // a user-defined adapted version of strcat that will copy from src to dest only till src reaches a space character or '\0'
}
}
}
I'm assuming here that is_1_vowel will be a function that goes over a single word (and not the whole line or file), and returns 1 if it satisfies the condition (has 1 vowel), and returns 0 otherwise.
Here's my final solution
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
void count1 (char* str)// count numbers of vowels for each word
{
for (int i = 0;;)
for (int v = 0, w = i;;)
{
int len;
char c = str[i++];
switch (c)
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
v++;
default:
continue;
case ' ':
case '\t':
case '\n':
case '\0':
len = i - 1 - w;
printf("'%.*s': %d characters, %d vowels\n", len, str+w, len, v );
if (c)
break;
else
return;
}
break;
}
}
void print_x(char* str, int n)
{
char* tmp;
unsigned int cnt = 0, stat = 0;
const char aeiou[] = "AEIOUaeiou";
while(*str)
{
switch(stat)
{
case 0://the word did not start
if (!isalpha(*str))
{
putchar(*str);
break;
}
stat = 1;
tmp = str;
cnt = 0;
case 1://the word started
if (strchr(aeiou, *str))
{
cnt++;
break;
}
if (! isalpha(*str))
{
if (cnt != n)
while(tmp <= str) putchar(*(tmp++));
else putchar(*str);
stat = 0;
}
} // end switch
++str;
}
if (stat)
{
--str;
if (cnt != n) while(tmp <= str) putchar(*(tmp++));
}
}
int main()
{
FILE *fp;
char line[128], line2[128];
int c=0, count[26]= {0}, x;
int n,a;
int i,j;
fp = fopen("test.txt", "r");
fscanf(fp, "%[^\n]", line);
fclose(fp);
printf("%s\n\n", line);
while (line[c] != '\0')
{
if (line[c] >= 'a' && line[c] <= 'z')
{
x = line[c] - 'a';
count[x]++;
}
c++;
}
for (c = 0; c < 26; c++)
{
printf("%c occurs %d times.\n", c + 'a', count[c]);
}
for (i = 0; i < 26; ++i)
{
for (j = i + 1; j < 26; ++j)
{
if (count[i] < count[j])
{
a = count[i];
count[i] = count[j];
count[j] = a;
}
}
}
printf("\n\n");
for (c = 0; c < 26; c++)
{
printf("%c occurs %d times.\n", c + 'a', count[c]);
}
printf("\n");
count1(line);
printf("\nInsert n: ");
scanf("%d", &n);
if (!(fp = fopen("./test.txt", "r")))
{
printf("unable open file\n");
return 1;
}
while (fgets(line, 128, fp))
print_x(line, n);
fclose(fp);
return 0;
}
I have the following problem: i have two switch statements. They work perfectly when separated, but the minute I put both of them into an if/else. switch always returns the default(error). I am sorry for the difficult wording, now I have copied in the whole program so you can check it, I have tried what you said, but it didn't seem to help. So for an example, when it asks for the number, my input is 2. Then it asks for what character do I want to choose (+,-,/,*), and no matter which I write in, it gives me the default output like I have type a wrong character.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
void tomb_beolvas(int *szamok);
void tomb_kiir(int *szamok);
void tomb_sorrend(int *szamok);
void sorrend_kiir(int *szamok);
void kalkulator(int *szamok);
int main() {
int szamok[10];
tomb_beolvas(szamok);
tomb_kiir(szamok);
tomb_sorrend(szamok);
sorrend_kiir(szamok);
kalkulator(szamok);
return 0;
}
void tomb_beolvas(int *szamok) {
int i;
srand(time(0));
for (i = 0; i < 10; i++) {
szamok[i] = rand() % (10) + 1;
}
return;
}
void tomb_kiir(int *szamok) {
int i;
for (i = 0; i < 10; i++) {
printf("%d\n", szamok[i]);
}
return;
}
void tomb_sorrend(int *szamok) {
int i;
int a, j;
for (i = 0; i < 10; ++i) {
for (j = i + 1; j < 10; j++) {
if (szamok[i] > szamok[j]) {
a = szamok[i];
szamok[i] = szamok[j];
szamok[j] = a;
}
}
}
return;
}
void sorrend_kiir(int *szamok) {
int i;
for (i = 0; i < 10; i++) {
printf("\n%d", szamok[i]);
}
return;
}
void kalkulator(int *szamok) {
char jel;
int a, b, donto;
printf("\nKerem valassza ki milyen modon szeretne megadni az adatokat:\n"
" 1.: egyben(peldaul 5. + 8.)\n"
" 2.: kulon(peldaul + aztan 5. es 8.)\n");
scanf("%d", &donto);
if (donto == 1) {
printf("\nKerem irja be hanyadik szamokat szeretne es koze hogy milyen kalkulaciot szeretne vegezni(pl.: 5 + 8):\n");
while (scanf("%d %c %d", &a, &jel, &b)) {
switch (jel) {
case '+':
printf("%d", szamok[a-1] + szamok[b-1]);
break;
case '-':
printf("%d", szamok[a-1] - szamok[b-1]);
break;
case '*':
printf("%d", szamok[a-1] * szamok[b-1]);
break;
case '/':
printf("%d", szamok[a-1] / szamok[b-1]);
break;
}
}
} else
if (donto == 2) {
printf("Adj meg egy jelet (+, -, *, /): ");
scanf("%c", &jel);
printf("add meg hanyadik szamokkal akarsz szamolni: ");
scanf("%d %d", &a, &b);
switch (jel) {
case '+':
printf("%d + %d = %d", szamok[a], szamok[b], szamok[a] + szamok[b]);
break;
case '-':
printf("%d - %d = %d", szamok[a], szamok[b], szamok[a] - szamok[b]);
break;
case '*':
printf("%d * %d = %d", szamok[a], szamok[b], szamok[a] * szamok[b]);
break;
case '/':
printf("%d / %d = %d", szamok[a], szamok[b], szamok[a] / szamok[b]);
break;
// operator doesn't match any case constant +, -, *, /
default:
printf("Error! operator is not correct");
}
}
return;
}
There is nothing wrong with your switch statements, however:
int szamok[]={};
You can't make an empty array, you should declare it with a size:
const int size = 10;
int szamok[10];
From what I can tell, you invoked undefined behavior by accessing szamok with an out of bounds index (which is any positive number, as you got an empty array).
I'm afraid your problem is a classic scanf() issue: instead of scanf("%c", &jel); you should use
scanf(" %c", &jel); // notice the initial space before the `%c`
This skips the newline left pending after the scanf("%d", &donto);.
I am writing a program that takes in a sudoku board that uses A-I instead of 1-9 and checks if the board is valid.
I read the sudoku board from a file and i used the switch to change all values to numbers.
My plan was to use atoi or sscanf to convert the 2D char array to a 2D int array so that i can add all the rows and columns to check if it is a valid board. However when using these functions i get the warnings:
expected type const char but argument is of type char or passing argumet one of sscanf makes pointer from integer without cast.
I'm still quite confused on pointers so idk what this really means. is it even possible to change my 2d char array to a 2d int array, if so any suggestions? if there is a better way to check if the board is valid suggestions would be greatly appreciated as well. Thanks
int main() {
int i, j;
char **matsudoku = malloc(9*sizeof(char*));
for (i=0; i<9; ++i)
matsudoku[i]=malloc(9*sizeof(char));
FILE *fpointer = fopen("C:/Users/Owner/Documents/Como Sci in C/sudokuchar.txt", "r");
if (fpointer == NULL) {
printf("Cannot open file \n");
exit(0);
}
for(i=0; i<9; i++){
for(j=0; j<9; j++){
fscanf(fpointer, " %c", &matsudoku[i][j]);
switch (matsudoku[i][j]){
case 'A':
matsudoku[i][j]='1';
break;
case 'B':
matsudoku[i][j]='2';
break;
case 'C':
matsudoku[i][j]='3';
break;
case 'D':
matsudoku[i][j]='4';
break;
case 'E':
matsudoku[i][j]='5';
break;
case 'F':
matsudoku[i][j]='6';
break;
case 'G':
matsudoku[i][j]='7';
break;
case 'H':
matsudoku[i][j]='8';
break;
case 'I':
matsudoku[i][j]='9';
break;
}
printf("%c",matsudoku[i][j]);
}
}
//atoi(matsudoku);
int k;
//or sscanf(matsudoku,"%d",%k);
fclose(fpointer);
}
I prefer this method without an atoi or a switch/case but instead exploits the nature of the ASCII table very directly. Simply read in a character but then subtract 'A'. So if the character was an 'A', then 'A' - 'A' is 0. But you mean this to be the "1" and thus, you add 1 here.
int main() {
int i, j;
char nextchar;
int **matsudoku = malloc(9*sizeof(int*));
for (i=0; i<9; ++i)
matsudoku[i]=malloc(9*sizeof(int));
FILE *fpointer = fopen("C:/Users/Owner/Documents/Como Sci in C/sudokuchar.txt", "r");
if (fpointer == NULL) {
printf("Cannot open file \n");
exit(0);
}
for(i=0; i<9; i++){
for(j=0; j<9; j++){
fscanf(fpointer, " %c", &nextchar);
matsodoku[i][j] = (int)(nextchar-'A') + 1;
printf("%d",matsudoku[i][j]);
}
}
fclose(fpointer);
}
There is really no reason to use a pointer-to-pointer-to-char to begin with when you can read the values directly into a 2D array of int. While there are many ways to approach this, sticking with your approach, you could simply do the following... read/validate each character from your file into a tmp value and then assign to matsudoku[i][j] = tmp - '0'; which will perform the character conversion in one step.
Putting it together, you could do something similar to the following:
#include <stdio.h>
#include <stdlib.h>
#define SDKSZ 9
int main (void)
{
int i, j;
int matsudoku[SDKSZ][SDKSZ] = {{0}};
FILE *fpointer =
fopen ("C:/Users/Owner/Documents/Como Sci in C/sudokuchar.txt", "r");
if (fpointer == NULL) {
printf ("Cannot open file \n");
exit (0);
}
for (i = 0; i < SDKSZ; i++)
for (j = 0; j < SDKSZ; j++) {
int tmp;
if (fscanf(fpointer, " %d", &tmp) != 1) { /* read/validate tmp */
fprintf (stderr, "error: on read matsudoku[%d][%d]\n", i, j);
exit (1);
}
matsudoku[i][j] = tmp - '0'; /* convert from ASCII to numeric */
}
fclose (fpointer);
for (i = 0; i < SDKSZ; i++) {
for (j = 0; j < SDKSZ; j++)
printf (" %3d", matsudoku[i][j]);
putchar ('\n');
}
return 0;
}
Let me know if you have any questions or problems (I didn't have data to test).
Instead of converting the letter characters to number characters, I'd make a new 2D array of type int:
int matSudokuInt[9][9];
for(i=0; i<9; i++)
{
for(j=0; j<9; j++)
{
fscanf(fpointer, " %c", &matsudoku[i][j]);
switch (matsudoku[i][j])
{
case 'A':
matSudokuInt[i][j]=1;
break;
case 'B':
matSudokuInt[i][j]=2;
break;
case 'C':
matSudokuInt[i][j]=3;
break;
case 'D':
matSudokuInt[i][j]=4;
break;
case 'E':
matSudokuInt[i][j]=5;
break;
case 'F':
matSudokuInt[i][j]=6;
break;
case 'G':
matSudokuInt[i][j]=7;
break;
case 'H':
matSudokuInt[i][j]=8;
break;
case 'I':
matSudokuInt[i][j]=9;
break;
}
printf("%d ", matSudokuInt[i][j]);
}
printf("\n");
}
Then it becomes easy to sum the rows and columns:
int sum = 0;
int rowSum[9];
int colSum[9];
// Let i be the column index and j be the row index
for (j = 0; j < 9; j++) {
sum = 0;
for (i = 0; i < 9; i++) {
sum += matSudokuInt[i][j];
}
rowSum[j] = sum;
}
for (i = 0; i < 9; i++) {
sum = 0;
for (j = 0; j < 9; j++) {
sum += matSudokuInt[i][j];
}
colSum[i] = sum;
}
You can then easily look through the sum arrays and check that all entries are equal.
I am making a game for school this is a basic slot machine it will randomly generate numbers and converts the numbers to chars in a separate array. This seems to not be working as the statement is completely ignored. It doesn't give the right output and some time they will just go to blanks.
Output:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
/*
George Mason
Slots
Date Started: 4/25/16
Date Finished:
Dr K.
*/
void loadScreen();
void spacer();
void tabSpacer();
void clearScr();
int printMachine(char*, int);
int randomNum(int*, int);
int convertNum(int*, char*, int);
int rand_int();
void game();
int main(){
srand(time(NULL));
int stop;
loadScreen();
clearScr();
game();
scanf("%d", &stop);
}
void game(){
int tokens = 5, randomNums[9], x, y = 9;
char randomChars[9], userInput;
randomNum(randomNums, 9);
convertNum(randomNums, randomChars, 9);
printMachine(randomChars, 9);
}
int printMachine(char* randomChars, int y){
printf("-------------\n");
printf("| %c | %c | %c | \n", randomChars[0], randomChars[1], randomChars[2]);
printf("| %c | %c | %c | \n", randomChars[3], randomChars[4], randomChars[5]);
printf("| %c | %c | %c | \n", randomChars[6], randomChars[7], randomChars[8]);
printf("-------------");
}
int randomNum(int* randomNums, int y){
int x,a = 0, b = 9;
for(x = 0; x < y; x++){
randomNums[x] = ((rand() % (b-a+1)) + a);
}
}
int convertNum(int* randomNums, char* randomChars, int y){
int x;
for(x = 0; x < 9; x++){
switch(randomNums[x]){
case 1:
randomChars[x] = '#';
break;
case 2:
randomChars[x] = '#';
break;
case 3:
randomChars[x] = '$';
break;
case 4:
randomChars[x] = '+';
break;
case 5:
randomChars[x] = '&';
break;
case 6:
randomChars[x] = '*';
break;
case 7:
randomChars[x] = '?';
break;
case 8:
randomChars[x] = '!';
break;
case 9:
randomChars[x] = '~';
break;
default:
randomChars[x] = 'e';
break;
}
}
}
void loadScreen(){
int x;
for(x = 0; x < 3; x++){
spacer();
}
tabSpacer();
printf("Please wait 5 seconds while we load the saved data.\n");
tabSpacer();
printf(" If there is no saved data one will be created.");
sleep(5);
}
void spacer(){
int x;
for(x = 0; x < 3; x++){
printf("\n");
}
}
void tabSpacer(){
printf("\t ");
}
void clearScr(){
system("cls");
}
You have forgot to keep break; after every case so it will run all cases i.e from case 1 to case 9.
At the end it will save randomChars[x] = '~'; (case 9).
case 1:
randomChars[x] = '#';
break;
case 2:
randomChars[x] = '#';
break;
.
.
.
.
case 7:
randomChars[x] = '?';
break;
case 8:
randomChars[x] = '!';
break;
case 9:
randomChars[x] = '~';
break;
EDIT:
why your function return type is int when you are not returning any value. change int to void.
function game() is not declared before main()
I am getting Output like this:
I am trying to carry out left to right evaluation in C. No order of precedence whatsoever. So 5+3*2 should be 16. I know how to do that with 2 numbers and an operator, however, I cannot figure out how to do the same thing for an expression like 2+4-5+2.
This is what I have for 2 numbers:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 20
int main(void)
{
char exp[SIZE];
int ans,c, i=0;
int length;
printf("Enter your expression: ");
fgets(exp, 20, stdin);
length = strlen(exp);
--length;
for(int j=0; j<length; j++)
{
while (exp[i]!='\n')
{
// putchar(exp[i]);
i++;
switch (exp[i])
{
case '+':
ans = (exp[i]-'0') + (exp[2]-'0');
printf("The answer is %d\n", ans);
break;
case '-':
ans = (exp[0]-'0') - (exp[2]-'0');
printf("The answer is %d\n", ans);
break;
case '*':
ans = (exp[0]-'0') * (exp[2]-'0');
printf("The answer is %d\n", ans);
break;
case '/':
ans = (exp[0]-'0') / (exp[2]-'0');
printf("The answer is %d\n", ans);
break;
default:
break;
}
}
}
exit(0);
}
Any help is appreciated.
Assuming alternating numbers and operators with single-character numbers (which seems to be what you assumed), a minimal implementation similar to your original implementation is:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 20
int main(void) {
char exp[SIZE];
int ans, length, i;
printf("Enter your expression: ");
fgets(exp, 20, stdin);
ans = exp[0] - '0';
length = strlen(exp) - 1;
for (i = 0; i < length && exp[i] != '\n'; i++) {
switch (exp[i]) {
case '+':
ans += exp[i+1] - '0';
break;
case '-':
ans -= exp[i+1] - '0';
break;
case '*':
ans *= exp[i+1] - '0';
break;
case '/':
ans /= exp[i+1] - '0';
break;
default:
break;
}
}
printf("The answer is %d\n", ans);
return 0;
}
As per your given example, assumed that each number will be single digit number.
Try this:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 20
int main(void)
{
char exp[SIZE];
int ans,c, i=0;
int length,j;
printf("Enter your expression: ");
fgets(exp, 20, stdin);
length = strlen(exp);
char ch;
ans = exp[i]-'0';
i++;
while (i <= length)
{
switch (exp[i])
{
case '+':
i++;
ans += (exp[i]-'0');
break;
case '-':
i++;
ans -=(exp[i]-'0');
break;
case '*':
i++;
ans *=(exp[i]-'0');
break;
case '/':
i++;
ans /= (exp[i]-'0');
break;
default:
break;
}
i++;
//printf("The answer is %d\n", ans);
}
printf("The answer is %d\n", ans);
exit(0);
}