Fzu problem 2102 solve equation

Source: Internet
Author: User

This question is very skillful in reading data. It is just like reading data with scanf, and then converting the number of reads into a 10-digit system according to the base system.

#include<cstdio>#include<cstring>#include<cctype>using namespace std;int main(){    //freopen("in.txt","r",stdin);    int cas,base,num1,num2;    char str1[50],str2[50];    scanf("%d",&cas);    while(cas--)    {        scanf("%s %s %d",str1,str2,&base);        num1=num2=0;        for(int i=0; str1[i]!='\0'; i++)        {    int a;            if(isalpha(str1[i]))            a=str1[i]-'a'+10;            else a=str1[i]-'0';            num1=num1*base+a;        }        for(int i=0; str2[i]!='\0'; i++)        {            int a;             if(isalpha(str2[i]))            a=str2[i]-'a'+10;            else a=str2[i]-'0';            num2=num2*base+a;        }        printf("(%d,%d)\n",num1/num2,num1%num2);    }    return 0;}

PS: This question teammate Wa is because the str1 and str2 arrays only open 10, and the array overflows.
"Higher Education Community Cup" third Fujian University Student Program Design Competition

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.