(C#)ACM考试题的第一题

哈哈!竟用C#写了。偷懒呀!以后还要用C语言再写一次。用C#写这个太简单了。

using  System;
using  System.Collections.Generic;
using  System.Text;
using  System.IO;

namespace  ACM1
{
    
class Program
    
{
        
static void Main(string[] args)
        
{
            
if(args.Length==0)
            
{
                Console.WriteLine(
"需要一个文本文件作为参数。格式,第一行为测试案例数,往后每行为测试案例。如|||,||");
                
return;
            }

            FileStream fs 
= new FileStream(args[0],FileMode.Open,FileAccess.Read);
            StreamReader sr 
= new StreamReader(fs);
            String s
=sr.ReadLine();
            
int N = int.Parse(s);
            
for (int i = 0; i < N; i++)
            
{
                s 
= sr.ReadLine();
                Console.WriteLine(s
+":"+ConvertNum(s));
            }


        }

        
static string ConvertNum(string str)
        
{
            
string[] s = str.Split(new char[] ','});
            
string num = "";
            
for (int i = 0; i < s.Length; i++)
            
{
                num
+=s[i].Length;
            }

            
char[] cs = num.ToCharArray();
            
int nums = 0;
            
for (int i = 1; i <= cs.Length; i++)
            
{
                nums 
+= int.Parse(cs[i - 1].ToString())*(int)Math.Pow(8,cs.Length-i);
            }

            
return nums.ToString();
        }

    }

}

转载于:https://www.cnblogs.com/zxsoft/archive/2007/10/26/938080.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值