1 solutions

  • 0
    @ 2025-11-5 15:48:14

    C++ :

    #include <stdio.h>
    #include <iostream>
    #include <math.h>
    #include <string>
    using namespace std;
    
    int main()
    {
    	int N;
    	int x, y;
    	string s;
    	int sjz;
    	scanf("%d", &N);
    	while (N--)
    	{
    		scanf("%d%d", &x, &y);
    		getchar();
    		if (y == x || y > 36)
    		{
    			printf("ERROR");
    		}
    		else
    		{
    			cin >> s;
    			sjz = 0;
    			int result[1000];
    			for (int i = s.length() - 1; i >= 0; i--)
    			{
    				if (s[i]>=65 && s[i]<=91)
    					sjz = (s[i] - 55) * (int)pow((double)x, s.length() - i - 1) + sjz;
    				else
    					sjz = (s[i] - 48) * (int)pow((double)x, s.length() - i - 1) + sjz;
    			}
    			int yushu;
    			int shang;
    			int i;
    			for (i = 0; sjz != 0; i++)
    			{
    				yushu = sjz%y;
    				sjz = sjz / y;
    				result[i] = yushu;
    			}
    			while (i--)
    			{
    				if (result[i]>=10)
    				   printf("%c", result[i]+55);
    				else
    					printf("%d", result[i]);
    			}
    		}	
    		if (N != 0)
    			printf("\n\n");
    	}
    	return 0;
    }
    
    • 1

    Information

    ID
    17188
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By