注意
以下は解答例として参考とするに留め、そのまま提出することは避けてください。
最適な解答ではないので恐らく写しても良い評価はでないでしょう。
今のところ課題難度は立堀>>>山口>上田>河内谷>玉井>伊地知、課題頻度は山口>立堀=玉井>河内谷>伊地知>上田
立堀は異色で面白そうですがrobocode入れてないので当面は課題やりません。
| 曜限(教員) | 講義ページ | 解答 |
|---|---|---|
| 月曜2限(河内谷) | * | 1 |
| 月曜2限(立堀) | * | ? |
| 月曜5限(増原) | * | 問題非公開 |
| 火曜1限(伊知地) | * | ? |
| 火木曜1限(開) | * | 1 2 m |
| 火曜5限(玉井) | * | 3 5 |
| 水曜5限(田中) | * | 問題非公開 |
| 木曜1限(植田) | * | 1 |
| 木曜5限(山口) | * | 4 |
| 金曜2限(上田) | * | 不明 |
|== クラスの番号表と現在の登録状況 == |番号 : 1 2 3 4 5 6 7 8 9 10 11 12 | : 月2 月2 月5 火1 火1 火5 水5 木1 木1 木5 金2 金2 |担当 :河内谷 立堀 増原 伊知地 開 玉井 田中 植田 開 山口 上田 久野 |定員 : 130 130 130 130 60 130 130 130 60 130 130 130 |追加 : 0 1 15 1 19 11 7 0 0 14 16 0 |抽選 :(130) (129) ( 62) (130) ( 28) (120) ( 47) (130) ( 60) (117) ( 55) ( 10)
import java.io.*;
class kadai3 {
public static void main(String args[]) throws IOException {
BufferedReader data=new BufferedReader(new InputStreamReader(System.in));
System.out.println("n=?");
int n=Integer.parseInt(data.readLine());
System.out.print(n);
do{
if(n%2==1)
n=n*3+1;
else
n/=2;
System.out.print(","+n);
}while(n>1);
System.out.println();
}
}
static void count() {
for(int i=0; i<M; i++)
for(int j=0; j<N; j++)
if( ground[i+1][j+1]==MINE )
for(int x=-1; x<=1; x++)
for(int y=-1; y<=1; y++)
if( ground[i+1+x][j+1+y]!=MINE )
ground[i+1+x][j+1+y]++;
}
import java.io.*;
class kadai1 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("student ID(except for the last alphabet:");
String str = br.readLine();
if (str.length() != 6) { System.err.println("Invalid input"); return; }
int d1,d2,d3,d4,d5,d6;
//1. 一の位を1桁目,十の位を2桁目,百の位を3桁目と数えることとする.
d1=Character.digit(str.charAt(5), 10);
d2=Character.digit(str.charAt(4), 10);
d3=Character.digit(str.charAt(3), 10);
d4=Character.digit(str.charAt(2), 10);
d5=Character.digit(str.charAt(1), 10);
d6=Character.digit(str.charAt(0), 10);
//奇数の桁に当たる数字をすべてたして3倍したものをpとする.
int p=(d1+d3+d5)*3;
//2. 偶数の桁の数字をそのままたしたものをqとする.
int q=d2+d4+d6;
//3. pとqをたしたものをrとする.
int r=p+q;
//4. rを10で割ったあまりをsとする.
int s=r%10;
//5. sが1ならA, 2ならB,3ならC,…9ならI,0ならJが求めるアルファベットとなる.
char c='A';
if(s==0)
s=10;
while(--s>0)
c++;
System.out.println("sutudent ID: "+str+c);
}
}
import java.io.*;
public class kadai4 {
public static void main(String[] args) throws Exception {
BufferedReader data = new BufferedReader(new InputStreamReader(System.in));
int computers_choice=0;
int players_choice=0, pc_prev=-1, pc_prev2=-1;
while(true){
//手を選ぶ(オプションA)
if( pc_prev!=-1&&pc_prev2!=-1){
if(pc_prev==pc_prev2)
computers_choice=(pc_prev==0)?2:(pc_prev-1);
else{
switch(pc_prev+pc_prev2){
case 1: //0,1
computers_choice=2;
break;
case 2: //0,2
computers_choice=1;
break;
case 3: //1,2
computers_choice=0;
break;
}
}
}else
computers_choice=(int)(Math.random()*3);
System.out.print("Your choice is(g=0, c=1, p=2):");
players_choice = Integer.parseInt(data.readLine());
System.out.println("My choice is "+computers_choice);
//手を記録
pc_prev2=pc_prev;
pc_prev=players_choice;
//判定
switch( (players_choice-computers_choice+3)%3 ){
case 0:
System.out.println("Draw!");
break;
case 1:
System.out.println("I win!");
break;
case 2:
System.out.println("You win!");
break;
}
}
}
}
import java.io.*;
public class cp1_tue1_kadai1 {
static public void main(String args[]) throws IOException{
System.out.println("解を求める1次方程式を入力して下さい");
String e = (new BufferedReader(new InputStreamReader(System.in))).readLine();
int ml=e.indexOf('*'), eq=e.indexOf('='), x=Math.max(e.indexOf('x'),e.indexOf('X'));
try{
if( ml<0 || eq<0 || x<0 )
throw new Exception("式が正しくありません");
int a=Integer.parseInt(e.substring(0,x-1));
int b=(e.charAt(x+1)=='+'?1:-1)*Integer.parseInt(e.substring(x+2,eq));
int c=Integer.parseInt(e.substring(eq+1,e.length()));
if( a==0 )
throw new Exception("xの係数が0");
System.out.println("x="+Double.toString((double)(c-b)/a));
}catch(Exception ex){
System.out.println(ex.getMessage());
}
}
}
import java.util.*;
import java.io.*;
public class cp1_hiraki_midtermtest {
static boolean readFile(String filename, Vector v){
try{
BufferedReader br = new BufferedReader(
new InputStreamReader(
new FileInputStream(filename)));
String tmp;
while( (tmp=br.readLine())!=null ){
try{
Integer i=Integer.valueOf(tmp);
v.add(i);
}catch(NumberFormatException e){
}
}
br.close();
}catch(Exception e){
System.out.println(e.getLocalizedMessage());
return false;
}
return true;
}
public static void main(String args[]){
if( args[0]==null ){
System.out.println("引数にファイルを指定してください");
return;
}
//ファイルから読み込む
Vector marks = new Vector();
readFile(args[0], marks);
//最小最大合計平均、ヒストグラム
int span=5;
int histogram[] = new int[100/span];
for(int i=0; i<100/span; i++) histogram[i]=0;
int min=-1, max=-1, sum=0;
double avg=0;
for(int i=0; i<marks.size(); i++){
int iv = ((Integer)marks.get(i)).intValue();
sum+=iv;
if(min==-1||min>iv) min=iv;
if(max==-1||max<iv) max=iv;
histogram[iv/span]++;
}
avg=((double)sum/marks.size());
//分散
double e2=0;
for(int i=0;i<marks.size();i++){
int iv = ((Integer)marks.get(i)).intValue();
e2+=Math.pow(iv-avg,2);
}
double variance=e2-Math.pow(avg,2);
System.out.println("データの個数"+marks.size());
System.out.println("最高点"+max);
System.out.println("最低点"+min);
System.out.println("合計"+sum);
System.out.println("平均点"+avg);
System.out.println("分散"+variance);
System.out.println("ヒストグラム:");
for(int i=0;i<100/span;i++){
String str=""+i*span;
if(str.length()==1) str+=" ";
System.out.print(str+" |");
for(int j=0;j<histogram[i];j++)
System.out.print("*");
System.out.println();
}
}
}