PAT甲级题库打卡—【最近考题A1132—后】—最新23.8.31

1 1132 Cut Integer

简单题,最后自己给自己挖了个坑。AC:

#include
using namespace std;

//模拟

typedef long long ll;

int main()
{
	int n;
	cin >> n;
	while(n--){
		string x;
		cin >> x;
		int x1 = stoi(x);
		
		int num = x.size() / 2;
		
		int left = 0,right = 0;
		int p = 1;
		
		for(int i = num - 1; i >= 0 ; i--)
		{
			left += (x[i] - '0')*p;
			right += (x[i+num] - '0')*p;
			p*=10;
		}
		

		if(left == 0 || right == 0)cout << "No" << endl; 
		else
		{
		//	if(x1 % left == 0 && x1 % right == 0) // 自己给自己挖坑 !! 想不到样例 但过不了 
			if(x1 % (left*right) == 0)  
				cout << "Yes" << endl;
			else cout << "No" << endl; 
		}
		
//		cout << left << " " << right << endl;

	}
	return 0;
} 

你可能感兴趣的:(PAT,算法)