標籤:
題目串連:點擊開啟連結
解題思路:
不可以用cin,會逾時
完整代碼:
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <set>using namespace std;const int INF = 1000000000;const int maxn = 10001; char s[maxn];int main(){ #ifdef DoubleQ freopen("in.txt" , "r" , stdin); #endif // DoubleQ while(~scanf("%s" , s)) { int len = strlen(s); for(int i = len - 1 ; i >= 0 ; i --) printf("%c",s[i]); printf("\n"); }}
題目串連:點擊開啟連結
解題思路:
暴力枚舉
完整代碼:
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <set>using namespace std;const int INF = 1000000000;const int maxn = 10001; char s[maxn];int main(){/* #ifdef DoubleQ freopen("in.txt" , "r" , stdin); #endif // DoubleQ */ for(int i = 0 ; i <= 9 ; i ++) { for(int j = 0 ; j <= 9 ; j ++) { for(int k = 0 ; k <= 9 ; k ++) { int a = i * 100 + j * 10 + k; int b = j * 100 + k * 10 + k; if(a + b == 532) { cout << i << " " << j << " " << k << endl; } } } }}
題目串連:點擊開啟連結
解題思路:
枚舉
完整代碼:
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <set>using namespace std;const int INF = 1000000000;const int maxn = 10001;int a[101] , b[101]; int check(int key){ int sum = 0; for(int i = 1 ; i < key ; i ++) { if(key % i == 0) sum += i; } if(sum == key) return 1; else if(sum > key) return 2; else return 0;} int main(){/* #ifdef DoubleQ freopen("in.txt" , "r" , stdin); #endif // DoubleQ */ int cnt1 = 0 , cnt2 = 0; for(int i = 2 ; i <= 60 ; i ++) { if(check(i) == 1) { a[cnt1++] = i; } else if(check(i) == 2) b[cnt2++] = i; } cout << "E: "; for(int i = 0 ; i < cnt1 ; i ++) printf("%d%s" , a[i] , i == cnt1 - 1 ? "\n" : " "); cout << "G: "; for(int i = 0 ; i < cnt2 ; i ++) printf("%d%s" , b[i] , i == cnt2 - 1 ? "\n" : " ");}
題目串連:點擊開啟連結
解題思路:
排序
完整代碼:
#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL; /** Constant List .. **/ //{ const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI; struct node{ string s; int old; int score;}q[1000001]; bool cmp(node a , node b){ if(a.score != b.score) return a.score > b.score; else if(a.s != b.s) return a.s > b.s; else return a.old > b.old;} int main(){ #ifdef DoubleQ freopen("in.txt","r",stdin); #endif int n; while(~scanf("%d",&n)) { for(int i = 0 ; i < n ; i ++) { cin >> q[i].s; scanf("%d%d",&q[i].old ,&q[i].score); } sort(q , q + n , cmp); for(int i = n - 1 ; i >= 0 ; i --) { cout << q[i].s << " " << q[i].old << " " << q[i].score << endl; } }}
2000年清華大學電腦研究生機試真題