In: Computer Science
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main() {
string userInput;
getline(cin, userInput);
// Declaring base
int N = 30;
if (userInput.length() > 10) {
cout << 0 << endl;
}
else {
int finalTotal = 0;
//Iterates through userInput
for(int i = 0; i < 10; i++){
char convertedInput = userInput[i];
// ASCII decimal value of each character
int asciiDec = int(convertedInput);
//Casts char value from input to int value
stringstream chr;
chr << convertedInput;
int temp;
chr >> temp;
// Sets whitespace value equal to zero
if(convertedInput == ' ') {
temp = 0;
}
//Converting to base 30 value
if (temp >= 1 && temp <= 10) {
temp = temp;
}
else if(asciiDec >= 65 && asciiDec <= 84) {
temp = asciiDec - 55;
}
else if(asciiDec >= 97 && asciiDec <= 116) {
temp = asciiDec - 87;
}
else {
temp = 0;
}
finalTotal += temp; //(1)
}
cout << finalTotal << endl;
}
return 0;
}
Accurate conversion from C++ to MIPS please
std::operator|(std::_Ios_Openmode, std::_Ios_Openmode):
daddiu $sp,$sp,-32
sd $fp,24($sp)
move $fp,$sp
move $3,$4
move $2,$5
sll $3,$3,0
sw $3,0($fp)
sll $2,$2,0
sw $2,4($fp)
lw $3,0($fp)
lw $2,4($fp)
or $2,$3,$2
move $sp,$fp
ld $fp,24($sp)
daddiu $sp,$sp,32
j $31
nop
main:
daddiu $sp,$sp,-496
sd $31,488($sp)
sd $fp,480($sp)
sd $28,472($sp)
sd $16,464($sp)
move $fp,$sp
lui $28,%hi(%neg(%gp_rel(main)))
daddu $28,$28,$25
daddiu $28,$28,%lo(%neg(%gp_rel(main)))
daddiu $2,$fp,24
move $4,$2
ld $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1Ev)($28)
move $25,$2
nop
daddiu $2,$fp,24
move $5,$2
ld $4,%got_disp(_ZSt3cin)($28)
ld $2,%call16(_ZSt7getlineIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE)($28)
move $25,$2
nop
li $2,30 # 0x1e
sw $2,8($fp)
daddiu $2,$fp,24
move $4,$2
ld $2,%call16(_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv)($28)
move $25,$2
nop
sltu $2,$2,11
xori $2,$2,0x1
andi $2,$2,0x00ff
beq $2,$0,.L4
nop
move $5,$0
ld $4,%got_disp(_ZSt4cout)($28)
ld $2,%call16(_ZNSolsEi)($28)
move $25,$2
nop
ld $5,%got_disp(_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)($28)
move $4,$2
ld $2,%call16(_ZNSolsEPFRSoS_E)($28)
move $25,$2
nop
b .L5
nop
.L4:
sw $0,0($fp)
sw $0,4($fp)
.L12:
lw $2,4($fp)
slt $2,$2,10
beq $2,$0,.L6
nop
lw $3,4($fp)
daddiu $2,$fp,24
move $5,$3
move $4,$2
ld $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm)($28)
move $25,$2
nop
lbu $2,0($2)
sb $2,12($fp)
lb $2,12($fp)
sw $2,16($fp)
li $5,8 # 0x8
li $4,16 # 0x10
ld $2,%got_disp(std::operator|(std::_Ios_Openmode, std::_Ios_Openmode))($28)
move $25,$2
nop
move $3,$2
daddiu $2,$fp,64
move $5,$3
move $4,$2
ld $2,%call16(_ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEC1ESt13_Ios_Openmode)($28)
move $25,$2
nop
lb $2,12($fp)
move $3,$2
daddiu $2,$fp,64
daddiu $2,$2,16
move $5,$3
move $4,$2
ld $2,%call16(_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c)($28)
move $25,$2
nop
daddiu $3,$fp,56
daddiu $2,$fp,64
move $5,$3
move $4,$2
ld $2,%call16(_ZNSirsERi)($28)
move $25,$2
nop
lb $3,12($fp)
li $2,32 # 0x20
bne $3,$2,.L7
nop
sw $0,56($fp)
.L7:
lw $2,56($fp)
blez $2,.L8
nop
lw $2,56($fp)
slt $2,$2,11
beq $2,$0,.L8
nop
lw $2,56($fp)
sw $2,56($fp)
b .L9
nop
.L8:
lw $2,16($fp)
slt $2,$2,65
bne $2,$0,.L10
nop
lw $2,16($fp)
slt $2,$2,85
beq $2,$0,.L10
nop
lw $2,16($fp)
addiu $2,$2,-55
sw $2,56($fp)
b .L9
nop
.L10:
lw $2,16($fp)
slt $2,$2,97
bne $2,$0,.L11
nop
lw $2,16($fp)
slt $2,$2,117
beq $2,$0,.L11
nop
lw $2,16($fp)
addiu $2,$2,-87
sw $2,56($fp)
b .L9
nop
.L11:
sw $0,56($fp)
.L9:
lw $2,56($fp)
lw $3,0($fp)
addu $2,$3,$2
sw $2,0($fp)
daddiu $2,$fp,64
move $4,$2
ld $2,%call16(_ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEED1Ev)($28)
move $25,$2
nop
lw $2,4($fp)
addiu $2,$2,1
sw $2,4($fp)
b .L12
nop
.L6:
lw $2,0($fp)
move $5,$2
ld $4,%got_disp(_ZSt4cout)($28)
ld $2,%call16(_ZNSolsEi)($28)
move $25,$2
nop
ld $5,%got_disp(_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)($28)
move $4,$2
ld $2,%call16(_ZNSolsEPFRSoS_E)($28)
move $25,$2
nop
.L5:
move $16,$0
daddiu $2,$fp,24
move $4,$2
ld $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev)($28)
move $25,$2
nop
move $2,$16
b .L18
nop
move $16,$4
daddiu $2,$fp,64
move $4,$2
ld $2,%call16(_ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEED1Ev)($28)
move $25,$2
nop
b .L15
nop
move $16,$4
.L15:
daddiu $2,$fp,24
move $4,$2
ld $2,%call16(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev)($28)
move $25,$2
nop
move $2,$16
move $4,$2
ld $2,%call16(_Unwind_Resume)($28)
move $25,$2
nop
.L18:
move $sp,$fp
ld $31,488($sp)
ld $fp,480($sp)
ld $28,472($sp)
ld $16,464($sp)
daddiu $sp,$sp,496
j $31
nop
__static_initialization_and_destruction_0(int, int):
daddiu $sp,$sp,-48
sd $31,40($sp)
sd $fp,32($sp)
sd $28,24($sp)
move $fp,$sp
lui $28,%hi(%neg(%gp_rel(__static_initialization_and_destruction_0(int, int))))
daddu $28,$28,$25
daddiu $28,$28,%lo(%neg(%gp_rel(__static_initialization_and_destruction_0(int, int))))
move $3,$4
move $2,$5
sll $3,$3,0
sw $3,0($fp)
sll $2,$2,0
sw $2,4($fp)
lw $3,0($fp)
li $2,1 # 0x1
bne $3,$2,.L21
nop
lw $3,4($fp)
li $2,65535 # 0xffff
bne $3,$2,.L21
nop
ld $2,%got_page(_ZStL8__ioinit)($28)
daddiu $4,$2,%got_ofst(_ZStL8__ioinit)
ld $2,%call16(_ZNSt8ios_base4InitC1Ev)($28)
move $25,$2
nop
ld $6,%got_disp(__dso_handle)($28)
ld $2,%got_page(_ZStL8__ioinit)($28)
daddiu $5,$2,%got_ofst(_ZStL8__ioinit)
ld $4,%got_disp(_ZNSt8ios_base4InitD1Ev)($28)
ld $2,%call16(__cxa_atexit)($28)
move $25,$2
nop
.L21:
nop
move $sp,$fp
ld $31,40($sp)
ld $fp,32($sp)
ld $28,24($sp)
daddiu $sp,$sp,48
j $31
nop
_GLOBAL__sub_I_main:
daddiu $sp,$sp,-32
sd $31,24($sp)
sd $fp,16($sp)
sd $28,8($sp)
move $fp,$sp
lui $28,%hi(%neg(%gp_rel(_GLOBAL__sub_I_main)))
daddu $28,$28,$25
daddiu $28,$28,%lo(%neg(%gp_rel(_GLOBAL__sub_I_main)))
li $5,65535 # 0xffff
li $4,1 # 0x1
ld $2,%got_page(__static_initialization_and_destruction_0(int, int))($28)
daddiu $2,$2,%got_ofst(__static_initialization_and_destruction_0(int, int))
move $25,$2
nop
move $sp,$fp
ld $31,24($sp)
ld $fp,16($sp)
ld $28,8($sp)
daddiu $sp,$sp,32
j $31
nop
DW.ref.__gxx_personality_v0:
I believe this is working well pls upvote