Java AC
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.StreamTokenizer; public class Main { /* * 1053 */ public static void main(String[] args) throws IOException { StreamTokenizer st = new StreamTokenizer(new BufferedReader( new InputStreamReader(System.in))); while (st.nextToken() != StreamTokenizer.TT_EOF) { int n = (int) st.nval; int matrix[][] = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { st.nextToken(); matrix[i][j] = (int) st.nval; } } for (int j = 0; j < n; j++) { int maxValue = matrix[j][j]; int maxCol = j; for (int i = j+1; i < n; i++) { if (matrix[i][j] > maxValue) { maxValue = matrix[i][j]; maxCol = i; } } for (int i = 0; i < n; i++) { int temp = matrix[j][i]; matrix[j][i] = matrix[maxCol][i]; matrix[maxCol][i] = temp; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n-1; j++) { System.out.print(matrix[i][j]+ " "); } System.out.print(matrix[i][n-1]); System.out.println(); } } } } /************************************************************** Problem: 1470 User: wzqwsrf Language: Java Result: Accepted Time:100 ms Memory:14868 kb ****************************************************************/C++ AC
#include <stdio.h> const int maxn = 12; int matrix[maxn][maxn]; int n,i,j; int main(){ while(scanf("%d",&n) != EOF){ for(i = 0; i < n; i++){ for(j = 0; j < n; j++){ scanf("%d",&matrix[i][j]); } } for (j = 0; j < n; j++) { int maxValue = matrix[j][j]; int maxCol = j; for (i = j+1; i < n; i++) { if (matrix[i][j] > maxValue) { maxValue = matrix[i][j]; maxCol = i; } } for (i = 0; i < n; i++) { int temp = matrix[j][i]; matrix[j][i] = matrix[maxCol][i]; matrix[maxCol][i] = temp; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n-1; j++) { printf("%d ",matrix[i][j]); } printf("%d",matrix[i][n-1]); printf("\n"); } } return 0; } /************************************************************** Problem: 1470 User: wangzhenqing Language: C++ Result: Accepted Time:0 ms Memory:1020 kb ****************************************************************/2、 题目1549:货币问题 时间限制:1 秒内存限制:128 兆特殊判题:否提交:430解决:240
Java AC
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.StreamTokenizer; public class Main { /* * 1053 */ public static void main(String[] args) throws IOException { StreamTokenizer st = new StreamTokenizer(new BufferedReader( new InputStreamReader(System.in))); while (st.nextToken() != StreamTokenizer.TT_EOF) { int p = (int) st.nval; int num = 0; int array[] = {100,50,20,10,5,2,1}; for (int i = 0; i < 7; i++) { if (p >= array[i]) { num += p / array[i]; p = p % array[i]; } } System.out.println(num); } } } /************************************************************** Problem: 1549 User: wzqwsrf Language: Java Result: Accepted Time:430 ms Memory:14872 kb ****************************************************************/C++ AC
#include <stdio.h> int main(){ int p; while(scanf("%d",&p) != EOF){ int array[7] = {100,50,20,10,5,2,1}; int num = 0; for(int i = 0; i < 7; i++){ if(p >= array[i]){ num += p / array[i]; p %= array[i]; } } printf("%d\n",num); } return 0; } /************************************************************** Problem: 1549 User: wangzhenqing Language: C++ Result: Accepted Time:30 ms Memory:1020 kb ****************************************************************/3、 题目1493:公约数
Java AC
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.StreamTokenizer; public class Main { /* * 1053 */ public static void main(String[] args) throws IOException { StreamTokenizer st = new StreamTokenizer(new BufferedReader( new InputStreamReader(System.in))); while (st.nextToken() != StreamTokenizer.TT_EOF) { int a = (int) st.nval; st.nextToken(); int b = (int) st.nval; int c = gcd(a, b); int num = 0; int i = 1; for(; i * i < c; i++){ if(c % i == 0){ num += 2; } } if(c == i * i){ num += 1; } System.out.println(num); } } private static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } } /************************************************************** Problem: 1493 User: wzqwsrf Language: Java Result: Accepted Time:290 ms Memory:15992 kb ****************************************************************/C++ AC
#include <stdio.h> int a,b; int gcd(int x, int y){ int temp; while(y > 0){ temp = x % y; x = y; y = temp; } return x; } int main(){ while(scanf("%d %d",&a, &b) != EOF){ int c = gcd(a,b); int num = 0; int i = 1; for(; i*i < c; i++){ if(c % i == 0){ num += 2; } } if(i * i == c){ num += 1; } printf("%d\n",num); } return 0; } /************************************************************** Problem: 1493 User: wangzhenqing Language: C++ Result: Accepted Time:10 ms Memory:1020 kb ****************************************************************/4、 题目1550:分糖果 时间限制:1 秒内存限制:128 兆特殊判题:否提交:486解决:86
Java AC
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.StreamTokenizer; public class Main { /* * 1053 */ public static void main(String[] args) throws IOException { StreamTokenizer st = new StreamTokenizer(new BufferedReader( new InputStreamReader(System.in))); while (st.nextToken() != StreamTokenizer.TT_EOF) { int n = (int) st.nval; int[] ratings = new int[n]; for (int i = 0; i < n; i++) { st.nextToken(); ratings[i] = (int) st.nval; } System.out.println(candy(ratings)); } } public static int candy(int[] ratings) { if (ratings == null || ratings.length == 0) { return 0; } int len = ratings.length; int candyNum[] = new int[len]; for (int i = 0; i < len; i++) { candyNum[i] = 1; } for (int i = 1; i < len; i++) { if (ratings[i] > ratings[i - 1]) { candyNum[i] = candyNum[i - 1] + 1; } } for (int i = len - 2; i >= 0; i--) { if (ratings[i] > ratings[i + 1] && candyNum[i] <= candyNum[i + 1]) { candyNum[i] = candyNum[i + 1] + 1; } } int allCandy = 0; for (int i = 0; i < len; i++) { allCandy += candyNum[i]; } return allCandy; } } /************************************************************** Problem: 1550 User: wzqwsrf Language: Java Result: Accepted Time:1040 ms Memory:27216 kb ****************************************************************/
C++ AC
#include <stdio.h> int n,i; int candy(int *ratings) { if(ratings == NULL || n == 0){ return 0; } int len = n; int *candyNum = new int[len]; for(i = 0; i < len; i++){ candyNum[i] = 1; } for(i = 1; i < len; i++){ if(ratings[i] > ratings[i-1]){ candyNum[i] = candyNum[i-1]+1; } } for(i = len-2; i >= 0; i--){ if(ratings[i] > ratings[i+1] && candyNum[i] <= candyNum[i+1]){ candyNum[i] = candyNum[i+1]+1; } } int allCandy = 0; for(i = 0; i < len; i++){ allCandy += candyNum[i]; } return allCandy; } int main(){ while(scanf("%d",&n) != EOF){ int *ratings = new int[n]; for(int i = 0; i < n; i++){ scanf("%d",&ratings[i]); } printf("%d\n",candy(ratings)); } return 0; } /************************************************************** Problem: 1550 User: wangzhenqing Language: C++ Result: Accepted Time:70 ms Memory:1552 kb ****************************************************************/