東方算程譚

Oriental Code Talk ── επιστημηが与太をこく、弾幕とは無縁のシロモノ。

目次

Blog 利用状況

ニュース

著作とお薦めの品々は

著作とお薦めの品々は
東方熱帯林へ。

あわせて読みたい

わんくま

  1. 東京勉強会#2
    C++/CLI カクテル・レシピ
  2. 東京勉強会#3
    template vs. generics
  3. 大阪勉強会#6
    C++むかしばなし
  4. 東京勉強会#7
    C++むかしばなし
  5. 東京勉強会#8
    STL/CLRによるGeneric Programming
  6. TechEd 2007 @YOKOHAMA
    C++・C++/CLI・C# 適材適所
  7. 東京勉強会#14
    Making of BOF
  8. 東京勉強会#15
    状態遷移
  9. 名古屋勉強会#2
    WinUnit - お気楽お手軽UnitTest

CodeZine

  1. Cで実現する「ぷちオブジェクト指向」
  2. CUnitによるテスト駆動開発
  3. SQLiteで組み込みDB体験(2007年版)
  4. C++/CLIによるCライブラリの.NET化
  5. C# 1.1からC# 3.0まで~言語仕様の進化
  6. BoostでC++0xのライブラリ「TR1」を先取りしよう (1)
  7. BoostでC++0xのライブラリ「TR1」を先取りしよう (2)
  8. BoostでC++0xのライブラリ「TR1」を先取りしよう (3)
  9. BoostでC++0xのライブラリ「TR1」を先取りしよう (4)
  10. BoostでC++0xのライブラリ「TR1」を先取りしよう (5)
  11. C/C++に対応した、もうひとつのUnitTestFramework ─ WinUnit
  12. SQLiteで"おこづかいちょう"
  13. STL/CLRツアーガイド
  14. マージ・ソート : 巨大データのソート法
  15. ヒープソートのアルゴリズム
  16. C++0xの新機能「ラムダ式」を次期Visual Studioでいち早く試す
  17. .NETでマンデルブロ集合を描く
  18. .NETでマンデルブロ集合を描く(後日談)
  19. C++/CLI : とある文字列の相互変換(コンバージョン)
  20. インテルTBBによる選択ソートの高速化
  21. インテルTBB3.0 によるパイプライン処理
  22. Visual C++ 2010に追加されたSTLアルゴリズム
  23. Visual C++ 2010に追加されたSTLコンテナ「forward_list」
  24. shared_ptrによるObserverパターンの実装
  25. .NETでマンデルブロ集合を描く(番外編) ── OpenCLで超並列コンピューティング
  26. StateパターンでCSVを読む
  27. 状態遷移表からStateパターンを自動生成する
  28. 「ソートも、サーチも、あるんだよ」~標準C++ライブラリにみるアルゴリズムの面白さ
  29. インテルTBBの同期メカニズム
  30. なぜsetを使っちゃいけないの?
  31. WPFアプリケーションで腕試し ~C++でもWPFアプリを
  32. C++11 : スレッド・ライブラリひとめぐり
  33. Google製のC++ Unit Test Framework「Google Test」を使ってみる
  34. メールでデータベースを更新するココロミ
  35. Visitorパターンで遊んでみたよ
  36. Collection 2題:「WPFにバインドできる辞書」と「重複を許す検索set」
  37. Visual C++ 2012:stateless-lambdaとSQLiteのぷち拡張
  38. 「Visual C++ Compiler November 2012 CTP」で追加された6つの新機能

@IT

  1. Vista時代のVisual C++の流儀(前編)Vista到来。既存C/C++資産の.NET化を始めよう!
  2. Vista時代のVisual C++の流儀(中編)MFCから.NETへの実践的移行計画
  3. Vista時代のVisual C++の流儀(後編) STL/CLRによるDocument/Viewアーキテクチャ
  4. C++開発者のための単体テスト入門 第1回 C++開発者の皆さん。テスト、ちゃんとしていますか?
  5. C++開発者のための単体テスト入門 第2回 C++アプリケーションの効率的なテスト手法(CppUnit編)
  6. C++開発者のための単体テスト入門 第3回 C++アプリケーションの効率的なテスト手法(NUnit編)

AWARDS


Microsoft MVP
for Visual Developer - Visual C++


Wankuma MVP
for いぢわる C++


Nyantora MVP
for こくまろ中国茶

Xbox

Links

記事カテゴリ

書庫

日記カテゴリ

以下について教えてあげよう♪

宿題だか課題だか知らないが、文字列変換問題ですな。

・大文字は小文字に、数字は'0','1','2'...を'9','8','7'...と反転させる。
・ただし、'#'以降の文字は変換しない。
・例として "Abc012_59F_#012Gh"を渡した場合の戻り値は "abc987_40f_#012Gh"となる。

ちょーしぶっこいてラムダ使って解いてみるなり。

#include <iostream>
#include <string>
#include <algorithm>

int main() {
  std::string str = "Abc012_59F_#012Gh";
  std::cout << '[' << str << ']' << std::endl;

  std::transform(
    str.begin(), 
    std::find(str.begin(),str.end(), '#'),
    str.begin(),
    [](char x) -> char {
      if ( x >= '0' && x <= '9' ) return '9' - x + '0';
      if ( x >= 'A' && x <= 'Z' ) return x - 'A' + 'a';
      return x;
    }
  );

  std::cout << '[' << str << ']' << std::endl;
}

投稿日時 : 2009年6月11日 23:11

コメントを追加

# re: 以下について教えてあげよう♪ 2009/06/11 23:41 倉田 有大

ああ、ラムダ式でつくってください!
と、掲示板にネタでかきこもうかなやんでいたところでした!
あざーす!

# re: 以下について教えてあげよう♪ 2009/06/11 23:54 επιστημη

どもー
STLの威力絶大っす♪。
std::stringがmutableなんで'#'で変換止めるのが楽ちん。

# re: 以下について教えてあげよう♪ 2009/06/12 0:02 neko

A~Zの文字コードは連続してるとは限らないのでstd::isupperなどを使おう。
(細かいことですが・・・)

# re: 以下について教えてあげよう♪ 2009/06/12 0:10 επιστημη

> A~Zの文字コードは連続してるとは限らない

仰せのとおりっす。
けどそれ言っちゃったら0~9だって連続してるとは限らんよなぁ...
武骨に変換表を引くのが上策かしら。

# re: 以下について教えてあげよう♪ 2009/06/12 1:11 yosapon

こんな複雑な条件をこんなに綺麗にまとめられるってすごいですね。
私がjavaとかでやったら大量のif文の羅列になりそうです。

# re: 以下について教えてあげよう♪ 2009/06/12 1:17 ゆーち

ラムダ式って、さっぱりわかんねぇです
orz

なんか、利得があるんでしょうか?

要件の通りによめるソースの方がよさげな気が(rya

# re: 以下について教えてあげよう♪ 2009/06/12 2:06 egtra

あれ?書き込まれていないみたいなんで、もう1度。0から9までは連続が保証されていますよ。AからZにはないですが。それともそういう常識が通用しない世界の話ではないですよね?

# re: 以下について教えてあげよう♪ 2009/06/12 6:02 επιστημη

> 要件の通りによめるソースの方がよさげな気が

「数なら反転/大文字は小文字/あるいはそのまま」
って要件の通りに読めるやん。↓

[](char x) -> char {
 if ( x >= '0' && x <= '9' ) return '9' - x + '0';
 if ( x >= 'A' && x <= 'Z' ) return x - 'A' + 'a';
 return x;
}

> 0から9までは連続が保証されていますよ。

そーなのかー。
現在/将来において存在するあらゆる文字コードにおいて'0'~'9'は連続すべし。
ってルールがあったのか。

# re: 以下について教えてあげよう♪ 2009/06/12 11:43 倉田 有大

ところでC#じゃ;が使えないんでしたっけ。ラムダ式で。

# re: 以下について教えてあげよう♪ 2009/06/12 11:49 倉田 有大

ああ、{}つかえば、使えるみたいですね。
ラムダ式むはむずかしいなっと。

# re: 以下について教えてあげよう♪ 2009/06/12 23:11 oki

すみません、'A' - 'Z' のコードが連続していない処理系ってなんですか? そんなもんがあったら、ASCII コードのテキストは流通できないんじゃないですか?

# re: 以下について教えてあげよう♪ 2009/06/12 23:14 oki

もしかして、EBCDIC の事???

# re: 以下について教えてあげよう♪ 2009/06/12 23:34 επιστημη

うん、まっさきにEBCDICが思い浮かんだデス。

# '0'-'9'が連続してない文字コードに
# お目にかかったことはないけれど、
# "連続してなければならん"ってルールは
# ないよねぇ。

# re: 以下について教えてあげよう♪ 2009/06/13 1:14 egtra

> 現在/将来において存在するあらゆる文字コードにおいて'0'~'9'は連続すべし。
そうなんですよね。いくらC/C++の標準がそう定めていたところで、
そうでない文字コードを採用したコンピュータの登場は妨げられないし、
その機種用のC/C++コンパイラはきっと規格のその部分を無視して実装されるんだろうなどうせと思います。

だから、自分には、規格のこの規定は違和感があるんですよね。
どうせこの規定がなかったとしても、自分のコードはASCII限定だ、この関数では0-9は連続と仮定しようという調子でコードを書くでしょうし。

# MuFNoNVVAT 2021/07/03 3:13 https://amzn.to/365xyVY

This blog is definitely entertaining additionally factual. I have picked up helluva helpful tips out of this amazing blog. I ad love to visit it again and again. Thanks!

# Illikebuisse gubuh 2021/07/04 15:26 pharmaceptica.com

buy erectile dysfunction pills online india https://www.pharmaceptica.com/

# ivermectin over the counter canada 2021/09/28 14:27 MarvinLic

ivermectin generic cream https://stromectolfive.com/# ivermectin for sale

# ivermectin 50 mg 2021/10/31 19:53 DelbertBup

ivermectin eye drops http://stromectolivermectin19.com/# cost of ivermectin pill
ivermectin pill cost

# ivermectin cream canada cost 2021/11/03 11:54 DelbertBup

ivermectin 50 http://stromectolivermectin19.com/# buy ivermectin for humans uk
ivermectin 1 cream generic

# sildenafil citrate tablets 100 mg http://viasild24.online/
2021/12/07 19:23 Nyusjdh

sildenafil citrate tablets 100 mg http://viasild24.online/

# bimatoprost 2021/12/11 23:29 Travislyday

http://baricitinibrx.com/ buy baricitinib

# buy bimatoprost 2021/12/12 18:38 Travislyday

http://baricitinibrx.online/ baricitinib eua fact sheet

# bimatoprost buy 2021/12/14 10:07 Travislyday

http://baricitinibrx.online/ baricitinib eua fact sheet

# bimatoprost generic best price 2021/12/15 4:11 Travislyday

http://stromectols.online/ stromectol 12mg

# cost of ivermectin cream 2021/12/16 19:55 Eliastib

jpvsdq https://stromectolr.com buy stromectol canada

# ivermectin cost 2021/12/18 17:28 Eliastib

scevaq https://stromectolr.com stromectol prices

# buy ivermectin uk http://stromectolabc.com/
where to buy stromectol online 2022/02/08 2:54 Busjdhj

buy ivermectin uk http://stromectolabc.com/
where to buy stromectol online

# buy doxycycline hyclate 100mg without a rx https://doxycyline1st.com/
doxycycline hyc 2022/02/26 8:33 Doxycycline

buy doxycycline hyclate 100mg without a rx https://doxycyline1st.com/
doxycycline hyc

# prednisone for sale online http://prednisoneen.store/ 2022/04/17 6:49 Prednisone

prednisone for sale online http://prednisoneen.store/

# biwtilqseofw 2022/06/01 6:32 tdocjjcw

mechanism of action of erythromycin http://erythromycinn.com/#

# ed pills https://erectionpills.best/
ed treatment review 2022/06/28 20:01 ErectionPills

ed pills https://erectionpills.best/
ed treatment review

# ed treatment pills https://erectiledysfunctionpills.shop/ 2022/10/14 22:54 Erectile

ed treatment pills https://erectiledysfunctionpills.shop/

# prednisone pack https://prednisone20mg.site/
buy prednisone 5mg canada 2022/11/15 18:03 Prednisone

prednisone pack https://prednisone20mg.site/
buy prednisone 5mg canada

# prednisone 2.5 mg daily https://prednisonepills.site/
prednisone 200 mg tablets 2022/11/28 23:57 Prednisone

prednisone 2.5 mg daily https://prednisonepills.site/
prednisone 200 mg tablets

# skycouger gf https://datingsiteonline.site/
best datings sites 2022/12/05 23:52 Tading

skycouger gf https://datingsiteonline.site/
best datings sites

# buying ed pills online https://edpills.science/
ed pills for sale 2023/01/07 13:54 EdPills

buying ed pills online https://edpills.science/
ed pills for sale

# free chat online singles https://datingonline1st.com/
best singles sites 2023/01/17 22:33 Dating

free chat online singles https://datingonline1st.com/
best singles sites

# Actual trends of drug. Everything what you want to know about pills.
https://canadianfast.com/
drug information and news for professionals and consumers. Get here. 2023/02/19 12:53 CanadaBest

Actual trends of drug. Everything what you want to know about pills.
https://canadianfast.com/
drug information and news for professionals and consumers. Get here.

# doors2.txt;1 2023/03/14 14:51 vhZoaJMlpFJyGG

doors2.txt;1

# non prescription https://pillswithoutprescription.pro/# 2023/05/16 4:49 PillsPro

non prescription https://pillswithoutprescription.pro/#

# trusted canadian pharmacies https://fastpills.pro/# canadian pharma companies 2023/06/29 17:49 FastPills

trusted canadian pharmacies https://fastpills.pro/# canadian pharma companies

# best pills for ed https://edpills.ink/# - buy erection pills 2023/07/26 20:09 EdPills

best pills for ed https://edpills.ink/# - buy erection pills

# pills for erection https://edpillsotc.store/# - herbal ed treatment 2023/10/07 21:19 EdPills

pills for erection https://edpillsotc.store/# - herbal ed treatment

# Abella Danger https://abelladanger.online/ abella danger video
2024/03/03 17:34 Adella

Abella Danger https://abelladanger.online/ abella danger video

タイトル
名前
URL
コメント