ZZULIOJ 1180-1198结构体专题 参考代码

一共19道题
虽然是java写的,但是还是用的类似于C的结构体
下面代码供参考

每题前面标的有题号
*1180 成绩统计(结构体专题)
1181 谁的年龄最小(结构体专题)
1182 查询记录(结构体专题)
1183 平面点排序(一)(结构体专题)
1184 平面点排序(二)(结构体专题)
1185 添加记录(结构体专题)
1186 删除记录(结构体专题)
1187 棒棒糖(结构体专题)
1188 选票统计(一)(结构体专题)
1189 选票统计(二)(结构体专题)
1190 按出生日期排序(结构体专题)
1191 数星星(结构体专题)
1192 奖学金(结构体专题)
1193 单科成绩排序(结构体专题)
1194 总成绩排序(结构体专题)
1195 猴子选大王(结构体专题)
1196 数星星(二)(结构体专题)
1197 考试排名(一)(结构体专题)
1198 考试排名(二)(结构体专题)

1180
import**** java.util.Scanner;

class student
{
	long num;
	String name;
	int x, y, z;
	int sum;
}

public class Main
{
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		student[] a = new student[110];
		int n, max = 0;
		n = cin.nextInt();
		for (int i = 1; i <= n; i++)
			a[i] = new student();
		for (int i = 1; i <= n; i++)
		{
			a[i].num = cin.nextLong();
			a[i].name = cin.next();
			a[i].x = cin.nextInt();
			a[i].y = cin.nextInt();
			a[i].z = cin.nextInt();
			a[i].sum = a[i].x + a[i].y + a[i].z;
			max = Math.max(a[i].sum, max);
		}
		for (int i = 1; i <= n; i++)
		{
			if (a[i].sum == max)
			{
				System.out.println(a[i].num + " " + a[i].name + " " + a[i].x + " " + a[i].y + " " + a[i].z);
				break;
			}
		}
	}
}





1181
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class friend
{
	String name;
	int x, y, z;
}

public class Main
{
	public static int check(friend a, friend b) {
		if (a.x != b.x)
		{
			if (a.x > b.x)
				return 1;
			else
				return 0;
		} else
		{
			if (a.y != b.y)
			{
				if (a.y > b.y)
					return 1;
				else
					return 0;
			} else
			{
				if (a.z > a.z)
					return 1;
				else
					return 0;
			}
		}
	}

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n;
		n = cin.nextInt();
		friend a[] = new friend[11];
		for (int i = 0; i <= 10; i++)
			a[i] = new friend();
		for (int i = 0; i < n; i++)
		{
			a[i].name = cin.next();
			a[i].x = cin.nextInt();
			a[i].y = cin.nextInt();
			a[i].z = cin.nextInt();
		}
		friend ans = new friend();
		ans.name = a[0].name;
		ans.x = a[0].x;
		ans.y = a[0].y;
		ans.z = a[0].z;
		for (int i = 1; i < n; i++)
		{
			if (check(a[i], ans) == 1)
				ans = a[i];
		}
		System.out.printf("%s %d-%02d-%02d", ans.name, ans.x, ans.y, ans.z);
	}
}
1182
import java.util.Scanner;

class student
{
	long num;
	String name;
	int x, y, z;
	int sum;
}

public class Main
{
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		student[] a = new student[110];
		int n, max = 0;
		n = cin.nextInt();
		for (int i = 1; i <= n; i++)
			a[i] = new student();
		for (int i = 1; i <= n; i++)
		{
			a[i].num = cin.nextLong();
			a[i].name = cin.next();
			a[i].x = cin.nextInt();
			a[i].y = cin.nextInt();
			a[i].z = cin.nextInt();
			a[i].sum = a[i].x + a[i].y + a[i].z;
			max = Math.max(a[i].sum, max);
		}
		int flag = 0;
		long qury = cin.nextLong();
		for (int i = 1; i <= n; i++)
		{
			if (a[i].num == qury)
			{
				System.out.println(a[i].num + " " + a[i].name + " " + a[i].x + " " + a[i].y + " " + a[i].z);
				flag = 1;
				break;
			}
		}
		if (flag == 0)
			System.out.println("Not Found");
	}
}


1183

import java.util.Scanner;

class node
{
	int x, y, z;
}

public class Main
{
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n;
		n = cin.nextInt();
		node[] a = new node[11];
		for (int i = 1; i <= 10; i++)
			a[i] = new node();
		for (int i = 1; i <= n; i++)
		{
			a[i].x = cin.nextInt();
			a[i].y = cin.nextInt();
			a[i].z = a[i].x * a[i].x + a[i].y * a[i].y;
		}
		for (int i = 1; i < n; i++)
			for (int j = 1; j < n; j++)
			{
				if (a[j].z > a[j + 1].z)
				{
					node t = a[j];
					a[j] = a[j + 1];
					a[j + 1] = t;
				}
			}
		for (int i = 1; i <= n; i++)
			System.out.print("(" + a[i].x + "," + a[i].y + ") ");
	}
}

1184


import java.util.Scanner;

class node
{
	int x, y;
}

public class Main
{
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n;
		n = cin.nextInt();
		node[] a = new node[1100];
		for (int i = 1; i <= 110; i++)
			a[i] = new node();
		for (int i = 1; i <= n; i++)
		{
			a[i].x = cin.nextInt();
			a[i].y = cin.nextInt();
		}
		for (int i = 1; i < n; i++)
			for (int j = 1; j <= n - i; j++)
			{
				if (a[j].x == a[j + 1].x)
				{
					if (a[j].y > a[j + 1].y)
					{
						node t = a[j];
						a[j] = a[j + 1];
						a[j + 1] = t;
					}
				} else if (a[j].x > a[j + 1].x)
				{
					node t = a[j];
					a[j] = a[j + 1];
					a[j + 1] = t;
				}
			}
		for (int i = 1; i <= n; i++)
			System.out.print("(" + a[i].x + "," + a[i].y + ") ");
		System.out.println();
		for (int i = n; i >= 1; i--)
			System.out.print("(" + a[i].x + "," + a[i].y + ") ");
	}
}

1185


import java.util.Scanner;

class node
{
	long num;
	String name;
	int x, y, z;
}

public class Main
{
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n;
		n = cin.nextInt();
		node[] a = new node[1010];
		for (int i = 1; i <= 1000; i++)
			a[i] = new node();
		for (int i = 1; i <= n; i++)
		{
			a[i].num = cin.nextLong();
			a[i].name = cin.next();
			a[i].x = cin.nextInt();
			a[i].y = cin.nextInt();
			a[i].z = cin.nextInt();
		}
		int flag = 0;
		n++;
		a[n].num = cin.nextLong();
		a[n].name = cin.next();
		a[n].x = cin.nextInt();
		a[n].y = cin.nextInt();
		a[n].z = cin.nextInt();
		for (int i = 1; i <= n - 1; i++)
		{
			if (a[i].num == a[n].num)
			{
				flag = 1;
				break;
			}
		}
		if (flag == 1)
			System.out.println("error!");
		else
		{
			for (int i = 1; i < n; i++)
			{
				for (int j = 1; j < n; j++)
				{
					if (a[j].num > a[j + 1].num)
					{
						node t = a[j];
						a[j] = a[j + 1];
						a[j + 1] = t;
					}
				}
			}
			for (int i = 1; i <= n; i++)
				System.out.println(a[i].num + " " + a[i].name + " " + a[i].x + " " + a[i].y + " " + a[i].z);
		}
	}
}

1186

import java.util.Scanner;

class node
{
	long num;
	String name;
	int x, y, z;
}

public class Main
{
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n;
		n = cin.nextInt();
		node[] a = new node[1010];
		for (int i = 1; i <= 1000; i++)
			a[i] = new node();
		for (int i = 1; i <= n; i++)
		{
			a[i].num = cin.nextLong();
			a[i].name = cin.next();
			a[i].x = cin.nextInt();
			a[i].y = cin.nextInt();
			a[i].z = cin.nextInt();
		}
		int flag = 0;
		long qury = cin.nextLong();
		for (int i = 1; i <= n; i++)
		{
			if (a[i].num == qury)
			{
				flag = 1;
				break;
			}
		}
		if (flag == 0)
			System.out.println("error!");
		else
		{
			for (int i = 1; i <= n; i++)
				if (a[i].num != qury)
					System.out.println(a[i].num + " " + a[i].name + " " + a[i].x + " " + a[i].y + " " + a[i].z);
				else
					continue;
		}
	}
}
1187

import java.util.Scanner;

class node
{
	double x, y;
}

public class Main
{
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int all;
		int n;
		all = cin.nextInt();
		n = cin.nextInt();
		node[] a = new node[110];
		for (int i = 1; i <= 15; i++)
			a[i] = new node();
		for (int i = 1; i <= n; i++)
		{
			a[i].x = cin.nextDouble();
			a[i].y = cin.nextDouble();
		}
		for (int i = 1; i < n; i++)
			for (int j = 1; j <= n - i; j++)
			{
				if (a[j].x > a[j + 1].x)
				{
					node t = a[j + 1];
					a[j + 1] = a[j];
					a[j] = t;
				}
			}
		double cost = 0;
		for (int i = 1; i <= n; i++)
		{
			if (all > a[i].y)
			{
				cost += a[i].x * a[i].y;
				all -= a[i].y;
			} else
			{
				cost += a[i].x * all;
				break;
			}
		}
		System.out.printf("%.2f", cost);
	}
}

1188


import java.util.Scanner;

public class Main
{
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n;
		int[] a = new int[10];
		String[] b = { "", "zhang", "wang", "zhao", "liu", "miao" };
		n = cin.nextInt();
		for (int i = 1; i <= n; i++)
		{
			String name;
			name = cin.next();
			if (name.compareTo("zhang") == 0)
				a[1]++;
			if (name.compareTo("wang") == 0)
				a[2]++;
			if (name.compareTo("zhao") == 0)
				a[3]++;
			if (name.compareTo("liu") == 0)
				a[4]++;
			if (name.compareTo("miao") == 0)
				a[5]++;
			// System.out.println(i+" "+name);
		}
		for (int i = 1; i <= 5; i++)
		{
			System.out.println(b[i] + " " + a[i]);
		}
	}
}

1189

import java.util.Scanner;
 
class node {
    String name;
    int num;
}
 
public class Main
{
 
    public static void main(String[] args) {
       Scanner cin = new Scanner(System.in);
        //String[] a = new String [510];
       int k = 0;
       node [] a= new node[530];
       for(int i = 1 ;i <= 510;i++)
           a[i] = new node ();
       int max=0;
       while(cin.hasNext())
       {
           int flag=0;
           String name = cin.next();
           if(name.compareTo("#")==0)
               break;
           for(int i = 1;i<=k;i++)
           {
               if(name.compareTo(a[i].name)==0)
               {
                   flag=1;
                   a[i].num++;
                   max=Math.max(max, a[i].num);
               }
           }
           if(flag==0)
           {
               a[++k].name=name;
               a[k].num++;
               max=Math.max(max, a[k].num);
           }
       }
       for(int i = 1;i<=k;i++)
           if(a[i].num==max)
           {
               System.out.println(a[i].name);
               break;
           }
    }
 
}

1190

import java.util.Scanner;

class node
{
	String name;
	int a, b, c;
}

public class Main
{
	public static void main(String[] args) {
		int n;
		Scanner cin = new Scanner(System.in);
		n = cin.nextInt();
		node[] a = new node[110];
		for (int i = 1; i <= 100; i++)
			a[i] = new node();
		for (int i = 1; i <= n; i++)
		{
			a[i].name = cin.next();
			a[i].a = cin.nextInt();
			a[i].b = cin.nextInt();
			a[i].c = cin.nextInt();
		}
		for (int i = 1; i < n; i++)
			for (int j = 1; j <= n - i; j++)
			{
				if (a[j].b == a[j + 1].b)
				{
					if (a[j].c > a[j + 1].c)
					{
						node t = a[j];
						a[j] = a[j + 1];
						a[j + 1] = t;
					}
				} else if (a[j].b > a[j + 1].b)
				{
					node t = a[j];
					a[j] = a[j + 1];
					a[j + 1] = t;
				}
			}
		for (int i = 1; i <= n; i++)
			System.out.printf("%s %d-%02d-%02d\n", a[i].name, a[i].a, a[i].b, a[i].c);
	}
}

1191


import java.util.Scanner;

class node
{
	int x, y;
}

public class Main
{
	public static void main(String[] args) {
		int n;
		Scanner cin = new Scanner(System.in);
		n = cin.nextInt();
		int k = 0;
		node[] a = new node[310];
		for (int i = 1; i <= 300; i++)
			a[i] = new node();
		for (int i = 1; i <= n; i++)
		{
			int flag = 0;
			int x, y;
			x = cin.nextInt();
			y = cin.nextInt();
			for (int j = 1; j <= k; j++)
			{
				if (a[j].x == x && a[j].y == y)
				{
					flag = 1;
					break;
				}
			}
			if (flag == 0)
			{
				a[++k].x = x;
				a[k].y = y;
			}
		}
		System.out.println(k);
	}
}

1192


import java.util.Scanner;

class node
{
	String name;
	int a, b;
	int x, y, z;
	int sum;
}

public class Main
{
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n;
		n = cin.nextInt();
		node[] a = new node[110];
		for (int i = 1; i <= 100; i++)
			a[i] = new node();
		int max = 0, total = 0;
		for (int i = 1; i <= n; i++)
		{
			a[i].name = cin.next();
			a[i].a = cin.nextInt();
			a[i].b = cin.nextInt();
			String c = cin.nextLine();
			if (c.charAt(1) == 'Y')
				a[i].x = 1;
			else
				a[i].x = 0;
			if (c.charAt(3) == 'Y')
				a[i].y = 1;
			else
				a[i].y = 0;
			if (c.length() == 7)
				a[i].z = 10;
			else
			{
				a[i].z = c.charAt(5) - '0';
			}
			if (a[i].a > 80 && a[i].z >= 1)
				a[i].sum += 8000;
			if (a[i].a > 85 && a[i].b > 80)
				a[i].sum += 4000;
			if (a[i].a > 90)
				a[i].sum += 2000;
			if (a[i].a > 85 && a[i].y == 1)
				a[i].sum += 1000;
			if (a[i].b > 80 && a[i].x == 1)
				a[i].sum += 850;
			// System.out.println(a[i].x+" "+a[i].y+" "+a[i].z);
			total += a[i].sum;
			max = Math.max(max, a[i].sum);
		}
		for (int i = 1; i <= n; i++)
		{
			if (a[i].sum == max)
			{
				System.out.println(a[i].name + "\n" + a[i].sum + "\n" + total);
				break;
			}
		}
	}
}

1193


import java.util.Scanner;

class node
{
	long num;
	String name;
	int a, b, c;
}

public class Main
{
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n;
		n = cin.nextInt();
		node[] a = new node[110];
		for (int i = 1; i <= 100; i++)
			a[i] = new node();
		for (int i = 1; i <= n; i++)
		{
			a[i].num = cin.nextLong();
			a[i].name = cin.next();
			a[i].a = cin.nextInt();
			a[i].b = cin.nextInt();
			a[i].c = cin.nextInt();
		}
		int flag;
		flag = cin.nextInt();
		if (flag == 1)
		{
			for (int i = 1; i <= n; i++)
				for (int j = 1; j <= n - i; j++)
				{
					if (a[j].a == a[j + 1].a)
					{
						if (a[j].num > a[j + 1].num)
						{
							node t = a[j + 1];
							a[j + 1] = a[j];
							a[j] = t;
						}
					} else if (a[j].a < a[j + 1].a)
					{
						node t = a[j + 1];
						a[j + 1] = a[j];
						a[j] = t;
					}
				}
		}
		if (flag == 2)
		{
			for (int i = 1; i <= n; i++)
				for (int j = 1; j <= n - i; j++)
				{
					if (a[j].b == a[j + 1].b)
					{
						if (a[j].num > a[j + 1].num)
						{
							node t = a[j + 1];
							a[j + 1] = a[j];
							a[j] = t;
						}
					} else if (a[j].b < a[j + 1].b)
					{
						node t = a[j + 1];
						a[j + 1] = a[j];
						a[j] = t;
					}
				}
		}
		if (flag == 3)
		{
			for (int i = 1; i <= n; i++)
				for (int j = 1; j <= n - i; j++)
				{
					if (a[j].c == a[j + 1].c)
					{
						if (a[j].num > a[j + 1].num)
						{
							node t = a[j + 1];
							a[j + 1] = a[j];
							a[j] = t;
						}
					} else if (a[j].c < a[j + 1].c)
					{
						node t = a[j + 1];
						a[j + 1] = a[j];
						a[j] = t;
					}
				}
		}
		for (int i = 1; i <= n; i++)
			System.out.println(a[i].num + " " + a[i].name + " " + a[i].a + " " + a[i].b + " " + a[i].c);
	}
}

1194


import java.util.Scanner;

class node
{
	long num;
	String name;
	int a, b, c, sum;
}

public class Main
{
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n;
		n = cin.nextInt();
		node[] a = new node[110];
		for (int i = 1; i <= 100; i++)
			a[i] = new node();
		for (int i = 1; i <= n; i++)
		{
			a[i].num = cin.nextLong();
			a[i].name = cin.next();
			a[i].a = cin.nextInt();
			a[i].b = cin.nextInt();
			a[i].c = cin.nextInt();
			a[i].sum = a[i].a + a[i].b + a[i].c;
		}
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n - i; j++)
			{
				if (a[j].sum == a[j + 1].sum)
				{
					if (a[j].name.compareTo(a[j + 1].name) > 0)
					{
						node t = a[j + 1];
						a[j + 1] = a[j];
						a[j] = t;
					}
				} else if (a[j].sum < a[j + 1].sum)
				{
					node t = a[j + 1];
					a[j + 1] = a[j];
					a[j] = t;
				}
			}
		for (int i = 1; i <= n; i++)
			System.out
					.println(a[i].num + " " + a[i].name + " " + a[i].a + " " + a[i].b + " " + a[i].c + " " + a[i].sum);
	}
}

1195

import java.util.Arrays;
import java.util.Scanner;

public class Main
{
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n, m, ans = 0;
		n = cin.nextInt();
		m = cin.nextInt();
		for (int i = 1; i <= n; i++)
			ans = (ans + m) % i;
		System.out.println(ans + 1);
	}
}
1196

import java.util.Arrays;
import java.util.Scanner;

class node
{
	double x, y;
}

public class Main
{
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n;
		int[] b = new int[100010];
		node[] a = new node[510];
		n = cin.nextInt();
		for (int i = 1; i <= 500; i++)
			a[i] = new node();
		for (int i = 1; i <= n; i++)
		{
			a[i].x = cin.nextDouble();
			a[i].y = cin.nextDouble();
		}
		int k = 0;
		int ans = 0;
		for (int i = 1; i < n; i++)
		{
			int cnt = 0;
			for (int j = i + 1; j <= n; j++)
			{
				for (int u = 1; u <= n; u++)
				{
					if ((a[j].x - a[i].x) * (a[u].y - a[i].y) == (a[u].x - a[i].x) * (a[j].y - a[i].y))
					{
						b[k]++;
					}
				}
				k++;
			}
		}
		// System.out.println(k);
		Arrays.sort(b, 0, k);
		System.out.println(b[k - 1]);
	}
}

1197

import java.util.Arrays;
import java.util.Scanner;

class node
{
	String name;
	int sum;
}

public class Main
{
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int[] s = new int[20];
		node[] a = new node[1110];
		for (int i = 1; i <= 1000; i++)
			a[i] = new node();
		int n, m, g, x = 0;
		n = cin.nextInt();
		m = cin.nextInt();
		g = cin.nextInt();
		for (int i = 1; i <= m; i++)
		{
			s[i] = cin.nextInt();
		}
		for (int i = 1; i <= n; i++)
		{
			int sum = 0;
			String name = cin.next();
			int k = cin.nextInt();
			for (int j = 1; j <= k; j++)
			{
				int d;
				d = cin.nextInt();
				sum += s[d];
			}
			node use = new node();
			use.name = name;
			use.sum = sum;
			a[++x] = use;
		}
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n - i; j++)
			{
				if (a[j].sum == a[j + 1].sum)
				{
					if (a[j].name.compareTo(a[j + 1].name) > 0)
					{
						node t = a[j + 1];
						a[j + 1] = a[j];
						a[j] = t;
					}
				} else if (a[j].sum < a[j + 1].sum)
				{
					node t = a[j + 1];
					a[j + 1] = a[j];
					a[j] = t;
				}
			}
		int cnt = 0;
		for (int i = 1; i <= n; i++)
		{
			if (a[i].sum < g)
				break;
			else
				cnt++;
		}
		System.out.println(cnt);
		for (int i = 1; i <= cnt; i++)
			System.out.println(a[i].name + " " + a[i].sum);
	}
}

1198


import java.util.Arrays;
import java.util.Scanner;

class node
{
	String name;
	int num;
	int sum;
}

public class Main
{
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		node[] a = new node[1100];
		for (int i = 1; i <= 1000; i++)
			a[i] = new node();
		int n, k = 0;
		n = cin.nextInt();
		while (cin.hasNext())
		{
			String name = cin.next();
			int time = 0, cnt = 0;
			for (int i = 1; i <= n; i++)
			{
				int sum = 0;
				int num = 0;
				String s = cin.next();
				String[] b = s.split("\\(|\\)");
				if (b.length == 1)
					sum = Integer.parseInt(s);
				else
				{
					sum = Integer.parseInt(b[0]);
					num = Integer.parseInt(b[1]);
				}
				if (sum > 0)
				{
					cnt++;
					time += sum + num * 20;
				}
			}
			// System.out.println(name+" "+cnt+" "+time);
			a[++k].name = name;
			a[k].num = cnt;
			a[k].sum = time;
		}
		for (int i = 1; i <= k; i++)
			for (int j = 1; j <= k - i; j++)
			{
				if (a[j].num == a[j + 1].num)
				{
					if (a[j].sum == a[j + 1].sum)
					{
						if (a[j].name.compareTo(a[j + 1].name) > 0)
						{
							node t = a[j + 1];
							a[j + 1] = a[j];
							a[j] = t;
						}
					} else if (a[j].sum > a[j + 1].sum)
					{
						node t = a[j + 1];
						a[j + 1] = a[j];
						a[j] = t;
					}
				} else if (a[j].num < a[j + 1].num)
				{
					node t = a[j + 1];
					a[j + 1] = a[j];
					a[j] = t;
				}
			}
		for (int i = 1; i <= k; i++)
			System.out.printf("%-10s %2d %4d\n", a[i].name, a[i].num, a[i].sum);
	}
}

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值