PAT刷题笔记

1090

#include 
#include 
#include 
using namespace std;
int main() {
    int n, k, t1, t2;
    map> m;
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) {
        scanf("%d%d", &t1, &t2);
        m[t1].push_back(t2);
        m[t2].push_back(t1);
    }
    while (k--) {
        int cnt, flag = 0, a[100000] = {0};
        scanf("%d", &cnt);
        vector v(cnt);
        for (int i = 0; i < cnt; i++) {
            scanf("%d", &v[i]);
            a[v[i]] = 1;
        }
        for (int i = 0; i < v.size(); i++)
            for (int j = 0; j < m[v[i]].size(); j++)
                if (a[m[v[i]][j]] == 1) flag = 1;
        printf("%s\n",flag ? "No" :"Yes");
    }
    return 0;
}

1091

#include 
#include 
using namespace std;
int main() {
    int m;
    cin >> m;
    while (m--) {
        int k, flag = 0;
        cin >> k;
        for (int n = 1; n < 10; n++) {
            int mul = n * k * k;
            string smul = to_string(mul), sk = to_string(k);
            string smulend = smul.substr(smul.length() - sk.length());
            if (smulend == sk) {
                printf("%d %d\n", n, mul);
                flag = 1;
                break;
            }
        }
        if (flag == 0) printf("No\n");
    }
    return 0;
}

1092

#include 
#include 
using namespace std;
int a[1005][105], sum[1005];
int main() {
    int m, n, maxn = 0, total = 0;
    vector ans;
    cin >> m >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> a[i][j];
            sum[j] += a[i][j];
            maxn = max(maxn, sum[j]);
        }
    }
    cout << maxn << endl;
    for (int i = 1; i <= m; i++)
        if (sum[i] == maxn) ans.push_back(i);
    for (int i = 0; i < ans.size(); i++) {
        if (i != 0) cout << " ";
        cout << ans[i];
    }
    return 0;
}

1093

#include 
#include 
using namespace std;

int main(){
	string s1,s2,s;
	getline(cin,s1);
	getline(cin,s2);
	s = s1 + s2;
	int hash[200] = {0};
	for(int i = 0;i

1094

#include
using namespace std;
int is(int number)
{
	for (int i = 2; i <= sqrt(number); i++)
	{
		if (number%i == 0)
		{
			return 0;
		}
	}
	return 1;
}
int main()
{
	int l, k, p;
	cin >> l >> k;
	string a, b;
	getchar();
	getline(cin, a);
	int len = a.length();
	for (int i = 0; i <= len - k; i++)
	{
		b = a.substr(i, k);
		p = atoi(b.c_str());
		if (is(p))
		{
			cout << b;
			return 0;
		}
	}
	cout << "404";
	return 0;
}

你可能感兴趣的:(学习笔记,PAT)