3 条题解
-
6
考场代码:
(
写得彳艮氵……,O2 差不多能 AC,许多地方可以优化。。)#include<bits/stdc++.h> using namespace std; //WRITTEN by S.H.Z. at 2023 NOIP exam int n_shz=0; //to save the number of words int l_shz=0; //to save the length of words char dic_shz[3010][3010]={}; //define a dictionary typed char to save words //define a compare fuction, to sort the words from big to small bool cmp1_shz(char a, char b){ return a>b; } //define a compare fuction, to sort the words from small to big bool cmp2_shz(char a, char b){ return a<b; } //define a compare fuction, to compare two words bool cmp3_shz(char a[], char b[]){ for(int i=0; i<l_shz; i++){ //comparing the words' letters one by one if(a[i] > b[i]) return 1; //if the letter of A is bigger, then word A must bigger than word B else if(a[i] < b[i]) return 0; //if the letter of A is smaller, then word A must smaller than word B else ; //if the letter of A is the same as B, then continue to compare until find a letter that is different } return 0; } int main(){ freopen("dict.in", "r", stdin); freopen("dict.out", "w", stdout); //STEP 1: INPUT scanf("%d%d", &n_shz, &l_shz); //inputting each word in range for(int i=0; i<n_shz; i++){ scanf("%s", dic_shz[i]); //sort the word's letters from big to small to deal with the next step of comparing sort(dic_shz[i], dic_shz[i]+l_shz, cmp1_shz); } //STEP 2: COMPARE for(int i=0; i<n_shz; i++){ char tent_shz[3010]={}; //to save the word in tent for(int j=0; j<l_shz; j++) tent_shz[j] = dic_shz[i][j]; //this time, sort the word's letters from small to big sort(tent_shz, tent_shz+l_shz, cmp2_shz); int flag_shz=1; //a flag to record if this word is smaller than the others, also the output result for(int j=0; j<n_shz; j++){ if(i == j) continue; //a word can not compare with itself //if there is a word bigger than this, then print zero if(cmp3_shz(tent_shz, dic_shz[j])){ flag_shz = 0; break; } } //STEP 3: OUTPUT //if there isn't, then print one printf("%d", flag_shz); } fclose(stdin); fclose(stdout); return 0; }
信息
- ID
- 2027
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- 递交数
- 48
- 已通过
- 10
- 上传者